mirror of
https://github.com/python/cpython.git
synced 2025-11-07 17:12:03 +00:00
gh-87790: support thousands separators for formatting fractional part of Decimal (#132202)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
0c3e3da195
commit
90a5b4402b
3 changed files with 28 additions and 1 deletions
|
|
@ -6122,7 +6122,11 @@ def _convert_for_comparison(self, other, equality_op=False):
|
|||
(?P<zeropad>0)?
|
||||
(?P<minimumwidth>\d+)?
|
||||
(?P<thousands_sep>[,_])?
|
||||
(?:\.(?P<precision>\d+))?
|
||||
(?:\.
|
||||
(?=[\d,_]) # lookahead for digit or separator
|
||||
(?P<precision>\d+)?
|
||||
(?P<frac_separators>[,_])?
|
||||
)?
|
||||
(?P<type>[eEfFgGn%])?
|
||||
\z
|
||||
""", re.VERBOSE|re.DOTALL)
|
||||
|
|
@ -6215,6 +6219,9 @@ def _parse_format_specifier(format_spec, _localeconv=None):
|
|||
format_dict['grouping'] = [3, 0]
|
||||
format_dict['decimal_point'] = '.'
|
||||
|
||||
if format_dict['frac_separators'] is None:
|
||||
format_dict['frac_separators'] = ''
|
||||
|
||||
return format_dict
|
||||
|
||||
def _format_align(sign, body, spec):
|
||||
|
|
@ -6334,6 +6341,11 @@ def _format_number(is_negative, intpart, fracpart, exp, spec):
|
|||
|
||||
sign = _format_sign(is_negative, spec)
|
||||
|
||||
frac_sep = spec['frac_separators']
|
||||
if fracpart and frac_sep:
|
||||
fracpart = frac_sep.join(fracpart[pos:pos + 3]
|
||||
for pos in range(0, len(fracpart), 3))
|
||||
|
||||
if fracpart or spec['alt']:
|
||||
fracpart = spec['decimal_point'] + fracpart
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue