Alex Rivera | Logout

Getting only 1 decimal place

Asked 2010-08-03T21:41:20.173
157

How do I convert 45.34531 to 45.3?

Edit
Report

2 Answers

253

Are you trying to represent it with only one digit:

print("{:.1f}".format(number)) # Python3
print "%.1f" % number          # Python2

or actually round off the other decimal places?

round(number,1)

or even round strictly down?

math.floor(number*10)/10
answered 2010-08-03T21:42:05.397
22
round(number, 1)
answered 2010-08-03T21:43:43.033

Your Answer