How to truncate/round-off decimal numbers?

MTD marc.t.davies at gmail.com
Tue Jun 20 05:26:47 EDT 2006


> The system cannot
> accurately represent some integers,

Er, I meant FLOATS. Doh.

Anyway, just to underline the example:

>>> x
0.66666666666666663
>>> s = str(round(x,2))
>>> s
'0.67'
>>> f = float(s)
>>> f
0.67000000000000004
>>> f == round(x,2)
True




More information about the Python-list mailing list