[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Formatting floating point

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).


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