Format a floating-point scalar as a decimal string in positional notation. Provides control over rounding, trimming and padding. Uses and assumes IEEE unbiased rounding. Uses the "Dragon4" algorithm. Parameters ---------- x : python float or numpy floating scalar V
(x, precision=None, unique=True,
fractional=True, trim='k', sign=False,
pad_left=None, pad_right=None, min_digits=None)
| 1129 | |
| 1130 | @set_module('numpy') |
| 1131 | def format_float_positional(x, precision=None, unique=True, |
| 1132 | fractional=True, trim='k', sign=False, |
| 1133 | pad_left=None, pad_right=None, min_digits=None): |
| 1134 | """ |
| 1135 | Format a floating-point scalar as a decimal string in positional notation. |
| 1136 | |
| 1137 | Provides control over rounding, trimming and padding. Uses and assumes |
| 1138 | IEEE unbiased rounding. Uses the "Dragon4" algorithm. |
| 1139 | |
| 1140 | Parameters |
| 1141 | ---------- |
| 1142 | x : python float or numpy floating scalar |
| 1143 | Value to format. |
| 1144 | precision : non-negative integer or None, optional |
| 1145 | Maximum number of digits to print. May be None if `unique` is |
| 1146 | `True`, but must be an integer if unique is `False`. |
| 1147 | unique : boolean, optional |
| 1148 | If `True`, use a digit-generation strategy which gives the shortest |
| 1149 | representation which uniquely identifies the floating-point number from |
| 1150 | other values of the same type, by judicious rounding. If `precision` |
| 1151 | is given fewer digits than necessary can be printed, or if `min_digits` |
| 1152 | is given more can be printed, in which cases the last digit is rounded |
| 1153 | with unbiased rounding. |
| 1154 | If `False`, digits are generated as if printing an infinite-precision |
| 1155 | value and stopping after `precision` digits, rounding the remaining |
| 1156 | value with unbiased rounding |
| 1157 | fractional : boolean, optional |
| 1158 | If `True`, the cutoffs of `precision` and `min_digits` refer to the |
| 1159 | total number of digits after the decimal point, including leading |
| 1160 | zeros. |
| 1161 | If `False`, `precision` and `min_digits` refer to the total number of |
| 1162 | significant digits, before or after the decimal point, ignoring leading |
| 1163 | zeros. |
| 1164 | trim : one of 'k', '.', '0', '-', optional |
| 1165 | Controls post-processing trimming of trailing digits, as follows: |
| 1166 | |
| 1167 | * 'k' : keep trailing zeros, keep decimal point (no trimming) |
| 1168 | * '.' : trim all trailing zeros, leave decimal point |
| 1169 | * '0' : trim all but the zero before the decimal point. Insert the |
| 1170 | zero if it is missing. |
| 1171 | * '-' : trim trailing zeros and any trailing decimal point |
| 1172 | sign : boolean, optional |
| 1173 | Whether to show the sign for positive values. |
| 1174 | pad_left : non-negative integer, optional |
| 1175 | Pad the left side of the string with whitespace until at least that |
| 1176 | many characters are to the left of the decimal point. |
| 1177 | pad_right : non-negative integer, optional |
| 1178 | Pad the right side of the string with whitespace until at least that |
| 1179 | many characters are to the right of the decimal point. |
| 1180 | min_digits : non-negative integer or None, optional |
| 1181 | Minimum number of digits to print. Only has an effect if `unique=True` |
| 1182 | in which case additional digits past those necessary to uniquely |
| 1183 | identify the value may be printed, rounding the last additional digit. |
| 1184 | |
| 1185 | -- versionadded:: 1.21.0 |
| 1186 | |
| 1187 | Returns |
| 1188 | ------- |
nothing calls this directly
no test coverage detected