bundles / numpy 2.4.4 / numpy / format_float_positional
function
numpy:format_float_positional
source: /numpy/_core/arrayprint.py :1212
Signature
def format_float_positional ( x , precision = None , unique = True , fractional = True , trim = k , sign = False , pad_left = None , pad_right = None , min_digits = None ) Summary
Format a floating-point scalar as a decimal string in positional notation.
Extended Summary
Provides control over rounding, trimming and padding. Uses and assumes IEEE unbiased rounding. Uses the "Dragon4" algorithm.
Parameters
x: python float or numpy floating scalarValue to format.
precision: non-negative integer or None, optionalMaximum number of digits to print. May be None if
uniqueisTrue, but must be an integer if unique isFalse.unique: boolean, optionalIf
True, use a digit-generation strategy which gives the shortest representation which uniquely identifies the floating-point number from other values of the same type, by judicious rounding. Ifprecisionis given fewer digits than necessary can be printed, or ifmin_digitsis given more can be printed, in which cases the last digit is rounded with unbiased rounding. IfFalse, digits are generated as if printing an infinite-precision value and stopping afterprecisiondigits, rounding the remaining value with unbiased roundingfractional: boolean, optionalIf
True, the cutoffs ofprecisionandmin_digitsrefer to the total number of digits after the decimal point, including leading zeros. IfFalse,precisionandmin_digitsrefer to the total number of significant digits, before or after the decimal point, ignoring leading zeros.trim: one of 'k', '.', '0', '-', optionalControls post-processing trimming of trailing digits, as follows:
'k'keep trailing zeros, keep decimal point (no trimming)
'.'trim all trailing zeros, leave decimal point
'0'trim all but the zero before the decimal point. Insert the zero if it is missing.
'-'trim trailing zeros and any trailing decimal point
sign: boolean, optionalWhether to show the sign for positive values.
pad_left: non-negative integer, optionalPad the left side of the string with whitespace until at least that many characters are to the left of the decimal point.
pad_right: non-negative integer, optionalPad the right side of the string with whitespace until at least that many characters are to the right of the decimal point.
min_digits: non-negative integer or None, optionalMinimum number of digits to print. Only has an effect if
unique=Truein which case additional digits past those necessary to uniquely identify the value may be printed, rounding the last additional digit.
Returns
rep: stringThe string representation of the floating point value
Examples
import numpy as np np.format_float_positional(np.float32(np.pi)) np.format_float_positional(np.float16(np.pi)) np.format_float_positional(np.float16(0.3)) np.format_float_positional(np.float16(0.3), unique=False, precision=10)✓
See also
- format_float_scientific
Aliases
-
numpy.format_float_positional