123.4+2=125.40000000000001

Ruud de Rooij * at spam.ruud.org
Wed Jun 21 07:13:44 EDT 2000


Peter Koppatz <pkop at brb.midat.de> writes:

> >>> 123.4+2
> 125.40000000000001   # is this OK?
> >>> print 123.4+2
> 125.4
> >>>
> 
> On my calculator: 123.4+2 = 125.4 !?
> I am using Python 1.6a2

>From http://www.python.org/1.6/

  The repr() of floating point numbers now gives full (17-digit)
  precision. This means that a number like 8.1 (which cannot be
  represented exactly in binary) will show up as 8.0999999999999996 when
  displayed using repr(). This shouldn't break any code but it may
  confuse users, especially since the interactive shell uses repr() to
  display all floating point results. Use str() or explicit precision in
  string format (e.g. "%.12g" % x) to see the the more familiar, rounded
  form.

Cut-n-paste'ly y'rs,

	- Ruud de Rooij.
-- 
ruud de rooij | *@spam.ruud.org | http://ruud.org



More information about the Python-list mailing list