Formatting floating point

Dave dboland9 at protonmail.com
Wed Sep 4 13:53:26 EDT 2019


On 9/4/19 1:38 PM, Rhodri James wrote:
> 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.
> 
Thanks Rhodri

Dave,



More information about the Python-list mailing list