[BangPypers] why is round() not working?

Dhananjay Nene dhananjay.nene at gmail.com
Fri Feb 19 08:51:02 CET 2010


On Fri, Feb 19, 2010 at 12:37 PM, Kenneth Gonsalves <lawgon at au-kbc.org>wrote:

> hi
>
> >>> round(2.1667000000000001,3)
> 2.1669999999999998
>
> what gives?
>
> round() gives you the closest approximation a floating point number can
achieve to the desired number ie. in this case 2.1669999999999998 is the
closest floating point representation to 2.17.

If one wants to have a specific precision, its better to use decimal.Decimal
package instead of floating points. eg. I prefer using decimal whenever
using the field to represent amounts (money).



> --
> regards
> Kenneth Gonsalves
> Senior Associate
> NRC-FOSS
> http://certificate.nrcfoss.au-kbc.org.in
> _______________________________________________
> BangPypers mailing list
> BangPypers at python.org
> http://mail.python.org/mailman/listinfo/bangpypers
>



-- 
--------------------------------------------------------
blog: http://blog.dhananjaynene.com
twitter: http://twitter.com/dnene
             http://twitter.com/_pythonic


More information about the BangPypers mailing list