Formatting floating point

Dave dboland9 at protonmail.com
Wed Sep 4 13:12:06 EDT 2019


All,

I have been going in circles trying to format a floating point number so 
there is only 1 decimal place.  In reading all of the gobble-gook that 
passes for Python advice, it looked like I should have done this:

numStr = '3.14159'
num = float(numstr)	# OK so far
numFmt = format(num, '{0:.1f}')		# Errors on format string
# --- Alternative that also does not work
numFmt = float("{0:.1f}".format(numStr))
# ---
numFmt = format(num, '0.1f')		# Does work

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

Thanks,
Dave




More information about the Python-list mailing list