浮点错误的解决方案
是否有一个很好的浮点错误解决方案?
如果我得到:
0.00831 + 0.000001 = 0.00831109999999999999
我可以避免这比通过比较2个数字长度更好的方法
小数点后使用toFixed()来匹配较短的数字和
另一个?
谢谢。
Is there a good solution for floating-point errors?
If I got:
0.00831 + 0.000001 = 0.00831109999999999999
can I avoid this by a better method than comparing 2 number length
after decimal point and using toFixed() to match shorter number with
another one?
Thanks.
7月23日下午4:35,vunet ... @ gmail.com写道:
On Jul 23, 4:35 pm, vunet...@gmail.com wrote:
是否有一个很好的浮点错误解决方案?
如果我得到:
0.00831 + 0.000001 = 0.00831109999999999999
我可以通过一个更好的方法避免这个比比较2个数字长度
小数点后使用toFixed()来匹配更短的数字和
另一个?
谢谢。
Is there a good solution for floating-point errors?
If I got:
0.00831 + 0.000001 = 0.00831109999999999999
can I avoid this by a better method than comparing 2 number length
after decimal point and using toFixed() to match shorter number with
another one?
Thanks.
是的。为了简单起见,在添加之前将每个乘以1000000:
8310 + 1 = 8311
Yes. To make it simpler, multiply each by 1000000 before adding:
8310 + 1 = 8311
On Jul 23,下午5:28,David Mark< dmark.cins ... @ gmail.comwrote:
On Jul 23, 5:28 pm, David Mark <dmark.cins...@gmail.comwrote:
7月23日下午4:35,vunet .. 。@ gmail.com写道:
On Jul 23, 4:35 pm, vunet...@gmail.com wrote:
是否有一个很好的浮点错误解决方案?
如果我得到:
0.00831 + 0.000001 = 0.00831109999999999999
我可以通过比小数点后的2号码长度
和使用toFixed()匹配更短的数字更好的方法来避免这种情况和另外一个
?
谢谢。
Is there a good solution for floating-point errors?
If I got:
0.00831 + 0.000001 = 0.00831109999999999999
can I avoid this by a better method than comparing 2 number length
after decimal point and using toFixed() to match shorter number with
another one?
Thanks.
是的。为了简单起见,在添加之前将每个乘以1000000:
8310 + 1 = 8311
Yes. To make it simpler, multiply each by 1000000 before adding:
8310 + 1 = 8311
非常好。谢谢。
very good. thank you.
David Mark在7/23/2007 5:28 PM发表以下内容:
David Mark said the following on 7/23/2007 5:28 PM:
7月23日下午4:35,vunet ... @ gmail.com写道:
On Jul 23, 4:35 pm, vunet...@gmail.com wrote:
>浮点数是否有一个很好的解决方案错误?
如果我得到:
0.00831 + 0.000001 = 0.00831109999999999999
我可以通过比小数点后的2个数字长度和使用toFixed()匹配更好的方法来避免这种情况更短的数字与另一个?
谢谢。
>Is there a good solution for floating-point errors?
If I got:
0.00831 + 0.000001 = 0.00831109999999999999
can I avoid this by a better method than comparing 2 number length
after decimal point and using toFixed() to match shorter number with
another one?
Thanks.
是的。为了简单起见,在添加之前将每个乘以1000000:
8310 + 1 = 8311
Yes. To make it simpler, multiply each by 1000000 before adding:
8310 + 1 = 8311
0.00831 + 0.000001!= 8311
-
兰迪
机会有利于准备好的心灵
comp.lang.javascript常见问题 - http://jibbering.com/faq/index.html
Javascript最佳实践 - http://www.JavascriptToolbox.com/ bestpractices /