There is ample evidence that, regardless of the language, programmers are
often looking for a way to suppress negative zero, and landing on a
variety of workarounds (pre-round, post-regex, etc.). A sampling:
* `How to have negative zero always formatted as positive zero in a
python string?`_ (Python, post-regex)
*`(Iron)Python formatting issue with modulo operator & "negative zero"`_
(Python, pre-round)
*`Negative sign in case of zero in java`_ (Java, post-regex)
*`Prevent small negative numbers printing as "-0"`_ (Objective-C, custom
number formatter)
What we would like instead is a first-class option to normalize negative
zero, on top of everything else that numerical string formatting already
offers.
.._`How to have negative zero always formatted as positive zero in a python string?`: https://stackoverflow.com/questions/11010683/how-to-have-negative-zero-always-formatted-as-positive-zero-in-a-python-string/36604981#36604981
.._`(Iron)Python formatting issue with modulo operator & "negative zero"`: https://stackoverflow.com/questions/41564311/ironpython-formatting-issue-with-modulo-operator-negative-zero/41564834#41564834
.._`Negative sign in case of zero in java`: https://stackoverflow.com/questions/11929096/negative-sign-in-case-of-zero-in-java
.._`Prevent small negative numbers printing as "-0"`: https://stackoverflow.com/questions/10969399/prevent-small-negative-numbers-printing-as-0
Rationale
=========
There are use cases where negative zero is unwanted in formatted number
output -- arguably, not wanting it is more common. Expanding the format
specification is the best way to support this because number formatting
already incorporates rounding, and the normalization of negative zero must
happen after rounding.
While it is possible to pre-round and normalize a number before formatting,
it's tedious and prone to error if the rounding doesn't precisely match
that of the format spec. Furthermore, functions that wrap formatting would
find themselves having to parse format specs to extract the precision
information. For example, consider how this utility for formatting
one-dimensional numerical arrays would be complicated by such pre-rounding:
..code-block:: python
def format_vector(v, format_spec='8.2f'):
"""Format a vector (any iterable) using given per-term format string."""
return f"[{','.join(f'{term:{format_spec}}' for term in v)}]"