[Tutor] Percentage

Jorge Godoy godoy at ieee.org
Tue Nov 8 12:59:31 CET 2005


Johan Geldenhuys <johan at accesstel.co.za> writes:

> Now that I have the answer (16.800000000000001), How do I round it of to 16.80
>      ? I only need it to be to the closest 1/100.

>>> print "%.2f" % 16.800000000000001
16.80
>>> a = 16.8000000000001
>>> b = "%.2f" % a
>>> b
'16.80'
>>> float(b)
16.800000000000001
>>> str(float(b))
'16.8'
>>> 

(The reason for the '000000000001' is because of the numeric base used to
represent data -- binary -- and the numeric base I'm requesting the answer to
be in -- decimal.)


Be seeing you,
-- 
Jorge Godoy      <godoy at ieee.org>



More information about the Tutor mailing list