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