Formatting floating point

Rhodri James rhodri at kynesim.co.uk
Wed Sep 4 13:38:36 EDT 2019


On 04/09/2019 18:12, Dave via Python-list wrote:
> My question is why, and where do I find a reliable source of information 
> on formatting numbers?  Not interested in replacement values like '{} 
> {}'.format(1, 2).

Here: 
https://docs.python.org/3/library/string.html#format-specification-mini-language

I suspect the thing you were overlooking was that format() expects to be 
given a format specification, and you gave it a format string.  Instead 
of format(num, "{0:.1f}"), you wanted format(num, ".1f").  If you had 
tried "{0:.1f}".format(num) instead, you would have found that worked too.

-- 
Rhodri James *-* Kynesim Ltd



More information about the Python-list mailing list