[issue45995] string formatting: normalize negative zero

John Belmonte report at bugs.python.org
Mon Dec 6 07:03:47 EST 2021


New submission from John Belmonte <john at neggie.net>:

proposal: add a string formatting option to normalize negative 0 values to 0

use case:  rounded display of a float that is nominally 0, where the distraction of a flashing minus sign from minute changes around 0 is unwanted

example:
>>> '%~5.1f' % -.00001
'  0.0'

format spec before:
  format_spec     ::=  [[fill]align][sign][#][0][width][grouping_option][.precision][type]
after:
  format_spec     ::=  [[fill]align][sign][~][#][0][width][grouping_option][.precision][type]
  where '~' is only allowed for number types

implementation: if '~' is present in the spec, add 0 to the value after applying precision

----------
components: Library (Lib)
messages: 407792
nosy: John Belmonte
priority: normal
severity: normal
status: open
title: string formatting: normalize negative zero
type: enhancement

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45995>
_______________________________________


More information about the Python-bugs-list mailing list