How to truncate/round-off decimal numbers?
Aahz
aahz at pythoncraft.com
Tue Jun 20 12:20:41 EDT 2006
In article <mailman.7238.1150794927.27775.python-list at python.org>,
Girish Sahani <girish at cse.iitb.ac.in> wrote:
>
>I want to truncate every number to 2 digits after the decimal point. I
>tried the following but it doesnt work.
>
>>>> a = 2
>>>> b = 3
>>>> round(a*1.0 / b,2)
>0.67000000000000004
>
>Inspite of specifying 2 in 2nd attribute of round, it outputs all the
>digits after decimal.
You should also consider switching to the decimal module if you care
about getting correct results.
--
Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/
"I saw `cout' being shifted "Hello world" times to the left and stopped
right there." --Steve Gonedes
More information about the Python-list
mailing list