[New-bugs-announce] [issue33731] string formatting that produces floats with preset precision while respecting locale

Jakub Szewczyk report at bugs.python.org
Fri Jun 1 08:42:33 EDT 2018


New submission from Jakub Szewczyk <jakub.szewczyk at gmail.com>:

.2f produces a string representation of a float rounded up to 2 significant digits.

>>> print ("{:.2f}".format(1.891))
1.89

However, it does not respect locale. There is no counterpart of 'f' that would respect locale. There is 'n', but because it follows the rules of 'g', in many cases it returns a different number of significant digits. 

>>> print ("{:.2n}".format(1.891))
1.9


In all my uses of formatted float printing, I need to produce floats that are rounded to have the same number of significant digits. I _presume_ this generalizes to the majority people, and the use of 'f' option is much more widespread than the use of 'g'. If this is the case, then a locale-friendly counterpart of 'f' would be very useful.

----------
components: Extension Modules
messages: 318407
nosy: Jakub Szewczyk, eric.smith
priority: normal
severity: normal
status: open
title: string formatting that produces floats with preset precision while respecting locale
type: enhancement
versions: Python 3.6

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


More information about the New-bugs-announce mailing list