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

Formatting floating point


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