[BangPypers] why is round() not working?
scorpion032 at gmail.com
Fri Feb 19 09:29:51 CET 2010
It is a standard IEEE-754 representation:
http://en.wikipedia.org/wiki/IEEE_754. This is the same that is followed by
In this representation, there are 53 bits available to store the precision;
so the closest number to the actual number is represented.
The arithmetic of floating points in interesting: This post by Wolfram
Alpha: http://blog.wolfram.com/2007/09/25/arithmetic-is-hard-to-get-right/ on
excel bugs is a good read, in this context.
On Fri, Feb 19, 2010 at 1:29 PM, Senthil Kumaran <orsenthil at gmail.com>wrote:
> On Fri, Feb 19, 2010 at 12:58:03PM +0530, Asokan Pichai wrote:
> > On Fri, Feb 19, 2010 at 12:37 PM, Kenneth Gonsalves <lawgon at au-kbc.org>
> > >>>> 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.
> 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.
> Q: What lies on the bottom of the ocean and twitches?
> A: A nervous wreck.
> BangPypers mailing list
> BangPypers at python.org
More information about the BangPypers