Why 3.0/5.0 = 0.59999...

Dale Strickland-Clark dale at riverhall.nospam.co.uk
Tue May 9 03:54:56 EDT 2006


Have you looked at the decimal module?

python
Python 2.4 (#1, Mar 22 2005, 21:42:42)
[GCC 3.3.5 20050117 (prerelease) (SUSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from decimal import *
>>> Decimal("3")/Decimal("5")
Decimal("0.6")
>>>

I don't suppose it is quick but it might do what you want.

Davy wrote:

> Hi all,
> 
> I used to be a Matlab user. And want to use Python to replace some
> Matlab work.
> 
> When I type 3.0/5.0, the result is 0.59999...
> 
> Is there some precision loss? And how to overcome it?
> 
> Any suggestions will be appreciated!
> Best regards,
> Davy

-- 
Dale Strickland-Clark
Riverhall Systems - www.riverhall.co.uk




More information about the Python-list mailing list