Javascript-计算错误 [英] Javascript - Calculation Error
本文介绍了Javascript-计算错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Chrome Javascript控制台中,输入以下内容:
In the Chrome Javascript Console I type the following:
3.1 * 3.68
返回的结果是:
11.408000000000001
为什么不显示结果
11.408
推荐答案
浮点错误是很正常的,这是由于用二进制表示某些浮点数所固有的问题.
Floating point errors are quite normal, this is due to the problems inherent in representing some floating point numbers in binary.
请阅读以下内容:每位计算机科学家应了解的浮点运算法则a>.
Read this: What Every Computer Scientist Should Know About Floating-Point Arithmetic.
这篇关于Javascript-计算错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文