Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
247 views
in Technique[技术] by (71.8m points)

Floating point error in representation?

when i make this multiplication

0.94 * 8700

the output is

8177.999999999999

but it should have been

8178

i'm using java , but i don't think this error is related to a particular Programming language now my question is ... why this happened ??
and what other numbers (just as an example) cause the same error?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The specific reason in your case is that the real number 0.94 cannot be represented exactly in a double precision floating point. When you type 0.94, the actual number stored is 0.939999999999999946709294817992486059665679931640625.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...