This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: wrong precision in float formatting or doc error
Type: Stage:
Components: Documentation, Interpreter Core Versions: Python 3.0, Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: georg.brandl Nosy List: georg.brandl, hagen
Priority: normal Keywords:

Created on 2008-07-18 10:40 by hagen, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (3)
msg69947 - (view) Author: Hagen Fürstenau (hagen) Date: 2008-07-18 10:40
This seems to be wrong:

>>> "{0:.2}".format(1.2345)
'1.2'

The same happens for format specifiers "g" and "n", but not for "f":

>>> "{0:.2f}".format(1.2345)
'1.23'

With empty format specifier it can even get really wrong:

>>> "{0:.1}".format(1.2345)
'1.0'
msg69948 - (view) Author: Hagen Fürstenau (hagen) Date: 2008-07-18 10:54
Just found it documented for the % operator: There precision is number
of digits before and after decimal point for format "g". 

But then the documentation for 2.6 is wrong:

"The precision is a decimal number indicating how many digits should be
displayed after the decimal point for a floating point value."
msg69949 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2008-07-18 11:15
Fixed docs in r65099.
History
Date User Action Args
2022-04-11 14:56:36adminsetgithub: 47654
2008-07-18 11:15:17georg.brandlsetstatus: open -> closed
resolution: fixed
messages: + msg69949
2008-07-18 10:54:22hagensettitle: wrong precision in float formatting -> wrong precision in float formatting or doc error
nosy: + georg.brandl
messages: + msg69948
assignee: georg.brandl
components: + Documentation
type: behavior ->
2008-07-18 10:40:25hagencreate