MCPcopy Index your code
hub / github.com/RustPython/RustPython / _format_number

Function _format_number

Lib/_pydecimal.py:6336–6376  ·  view source on GitHub ↗

Format a number, given the following data: is_negative: true if the number is negative, else false intpart: string of digits that must appear before the decimal point fracpart: string of digits that must come after the point exp: exponent, as an integer spec: dictionary resultin

(is_negative, intpart, fracpart, exp, spec)

Source from the content-addressed store, hash-verified

6334 return ''
6335
6336def _format_number(is_negative, intpart, fracpart, exp, spec):
6337 """Format a number, given the following data:
6338
6339 is_negative: true if the number is negative, else false
6340 intpart: string of digits that must appear before the decimal point
6341 fracpart: string of digits that must come after the point
6342 exp: exponent, as an integer
6343 spec: dictionary resulting from parsing the format specifier
6344
6345 This function uses the information in spec to:
6346 insert separators (decimal separator and thousands separators)
6347 format the sign
6348 format the exponent
6349 add trailing '%' for the '%' type
6350 zero-pad if necessary
6351 fill and align if necessary
6352 """
6353
6354 sign = _format_sign(is_negative, spec)
6355
6356 frac_sep = spec['frac_separators']
6357 if fracpart and frac_sep:
6358 fracpart = frac_sep.join(fracpart[pos:pos + 3]
6359 for pos in range(0, len(fracpart), 3))
6360
6361 if fracpart or spec['alt']:
6362 fracpart = spec['decimal_point'] + fracpart
6363
6364 if exp != 0 or spec['type'] in 'eE':
6365 echar = {'E': 'E', 'e': 'e', 'G': 'E', 'g': 'e'}[spec['type']]
6366 fracpart += "{0}{1:+}".format(echar, exp)
6367 if spec['type'] == '%':
6368 fracpart += '%'
6369
6370 if spec['zeropad']:
6371 min_width = spec['minimumwidth'] - len(fracpart) - len(sign)
6372 else:
6373 min_width = 0
6374 intpart = _insert_thousands_sep(intpart, spec, min_width)
6375
6376 return _format_align(sign, intpart+fracpart, spec)
6377
6378
6379##### Useful Constants (internal use only) ################################

Callers 1

__format__Method · 0.85

Calls 6

_format_signFunction · 0.85
lenFunction · 0.85
_insert_thousands_sepFunction · 0.85
_format_alignFunction · 0.85
joinMethod · 0.45
formatMethod · 0.45

Tested by

no test coverage detected