Reputation: 115
I am using python 3.4 and I want to limiting the a float number to two decimal points
round(1.2377, 2)
format(1.2377, '.2f')
These two would give my 1.24, but I don't want 1.24, I need 1.23, how do I do it?
Upvotes: 0
Views: 1678
Reputation: 107287
You can convert to string and slice then convert to float :
>>> num=1.2377
>>> float(str(num)[:-2])
1.23
read more about Floating Point Arithmetic: Issues and Limitations
Upvotes: 1