tags:

views:

77

answers:

3

how do i convert 45.34531 to 45.3?

+8  A: 

Are you trying to represent it with only one digit:

print "%.1f" % number

or actually round off the other decimal places?

round(number,1)

or even round strictly down?

math.floor(number*10)/10
relet
A: 
round(number, 1)
DixonD
+1  A: 
>>> "{0:0.1f}".format(45.34531)
'45.3'

Or use the builtin round:

>>> round(45.34531, 1)
45.299999999999997
The MYYN