floating point rounding

John Henry john106henry at hotmail.com
Fri Mar 9 22:58:09 CET 2007


On Mar 9, 5:45 am, hg <h... at nospam.org> wrote:
> hg wrote:
> > Hi,
>
> > Here is my issue:
>
> > f = 1.5 * 0.01
> > f
> >>> 0.014999999999999999
> > '%f' % f
> >>>'0.015000'
>
> > But I really want to get 0.02 as a result ... is there a way out ?
>
> > Thanks,
>
> > hg
>
> round


Or more precisely:

round(0.014999999999999999,2)

if that's what you wish to do.




More information about the Python-list mailing list