MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / _format_number

Function _format_number

tools/python-3.11.9-amd64/Lib/_pydecimal.py:6365–6400  ·  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 re

(is_negative, intpart, fracpart, exp, spec)

Source from the content-addressed store, hash-verified

6363 return ''
6364
6365def _format_number(is_negative, intpart, fracpart, exp, spec):
6366 """Format a number, given the following data:
6367
6368 is_negative: true if the number is negative, else false
6369 intpart: string of digits that must appear before the decimal point
6370 fracpart: string of digits that must come after the point
6371 exp: exponent, as an integer
6372 spec: dictionary resulting from parsing the format specifier
6373
6374 This function uses the information in spec to:
6375 insert separators (decimal separator and thousands separators)
6376 format the sign
6377 format the exponent
6378 add trailing '%' for the '%' type
6379 zero-pad if necessary
6380 fill and align if necessary
6381 """
6382
6383 sign = _format_sign(is_negative, spec)
6384
6385 if fracpart or spec['alt']:
6386 fracpart = spec['decimal_point'] + fracpart
6387
6388 if exp != 0 or spec['type'] in 'eE':
6389 echar = {'E': 'E', 'e': 'e', 'G': 'E', 'g': 'e'}[spec['type']]
6390 fracpart += "{0}{1:+}".format(echar, exp)
6391 if spec['type'] == '%':
6392 fracpart += '%'
6393
6394 if spec['zeropad']:
6395 min_width = spec['minimumwidth'] - len(fracpart) - len(sign)
6396 else:
6397 min_width = 0
6398 intpart = _insert_thousands_sep(intpart, spec, min_width)
6399
6400 return _format_align(sign, intpart+fracpart, spec)
6401
6402
6403##### Useful Constants (internal use only) ################################

Callers 1

__format__Method · 0.85

Calls 4

_format_signFunction · 0.85
_insert_thousands_sepFunction · 0.85
_format_alignFunction · 0.85
formatMethod · 0.45

Tested by

no test coverage detected