简体   繁体   English

表示中的浮点错误?

[英]Floating point error in representation?

when i make this multiplication 当我进行乘法时

0.94 * 8700 0.94 * 8700

the output is 输出是

8177.999999999999 8177.999999999999

but it should have been 但应该是

8178 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 ?? 我正在使用Java,但我不认为此错误与特定的编程语言相关,现在我的问题是...为什么发生这种情况?
and what other numbers (just as an example) cause the same error? 还有哪些其他数字(仅作为示例)会导致相同的错误?

The specific reason in your case is that the real number 0.94 cannot be represented exactly in a double precision floating point. 您遇到的具体原因是,不能以双精度浮点数精确表示实数0.94。 When you type 0.94 , the actual number stored is 0.939999999999999946709294817992486059665679931640625 . 键入0.94 ,实际存储的数字为0.939999999999999946709294817992486059665679931640625

It isn't an error. 这不是错误。 IEEE floats can't represent decimal numbers exactly. IEEE浮点数不能精确表示十进制数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM