1.090516455488E9 / 1000000.000 ???

Georg Brandl g.brandl-nospam at gmx.net
Tue Mar 28 16:52:39 CEST 2006


Math wrote:
> Hello,
> 
> I got a simple and probably stupid newby question..
> When I compute: 
> 1.090516455488E9 / 1000000
> the result is 1090516455.49
> Should be 1090516455.488
> 
> I know something with float and //...
> 
> Anybody?
> How do I get correct number?

Python 2.4.2 (#1, Mar 12 2006, 00:14:41)
[GCC 3.4.5 (Gentoo 3.4.5-r1, ssp-3.4.5-1.0, pie-8.7.9)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 1.090516455488E15 / 1000000
1090516455.4879999
>>> print 1.090516455488E15 / 1000000
1090516455.49

print is using str() which formats the float number with 12 digits
precision and therefore rounds the result.
repr() however, which is used by the interpreter when printing
out expression results, uses 17 digits precision which is why
you can see how the result is stored in the computer's memory
(1090516455.487999999999999....).

Georg



More information about the Python-list mailing list