Why 3.0/5.0 = 0.59999...

D

Davy

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
 
D

Dale Strickland-Clark

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.
I don't suppose it is quick but it might do what you want.
 
M

Mirco Wahab

Hi Davy
When I type 3.0/5.0, the result is 0.59999...
try:
0.6

Is there some precision loss? And how to overcome it?

Make sure the result gets piped
through some floating point con-
version (like print, %s etc.)

BTW, the 0.59999999999999998 value
is the "exact" calculated value
corresponding to your floating point
accuracy (34/2 digits).


Regards

Mirco
 
G

Grant Edwards

When I type 3.0/5.0, the result is 0.59999...

Is there some precision loss? And how to overcome it?

Doesn't anybody read the FAQ? Or even browse through current
threads before posting?

Sheesh. This has been in the FAQ forever, and was answered
again in the group just yesterday.
Any suggestions will be appreciated!

I doubt it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top