On Fri, Feb 19, 2010 at 12:58:03PM +0530, Asokan Pichai wrote:
> On Fri, Feb 19, 2010 at 12:37 PM, Kenneth Gonsalves <law...@au-kbc.org> wrote:
> >>>> round(2.1667000000000001,3)
> > 2.1669999999999998
> 
> >>> print "%5.3f" %(round(2.16670000001, 3))
> 2.167
> 

And if you want a safer way to deal with floating point numbers and to
kind of behavior we understand while doing it with paper and pencil,
use the Decimal module.

http://docs.python.org/library/decimal.html

It behaves well with normal ints, floats and is supported for all
standard operations which are applicable for ints and floats.

Decimal module was aimed towards the use-cases which deal with finance
and astronomy/ scientific computing where decimal number behavior
needs to be consistent and should not be system dependent.

-- 
Senthil
Q:      What lies on the bottom of the ocean and twitches?
A:      A nervous wreck.
_______________________________________________
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers

Reply via email to