奇怪的行为,乘以小数(IE) [英] Strange behaviour, multiplying decimals (IE)
问题描述
我正在为内联网构建一个以IE为中心的门户,所以我只需要为IE 6开发
+
我的版本是:6.00290.2180
这就是我所看到的:
>
0.25 * 100 = 25
0.26 * 100 = 26
0.27 * 100 = 27
确定如此远......
0.28 * 100 = 28.000000000000003
0.29 * 100 = 28.999999999999996
不是我的预期。 />
奇怪的是,0.299产生了我的期望,29.9
另外,0.299 * 1000 = 299,这是正确的!
我从0.01迭代到0.99,这些其他组合产生了类似的输出:
0.07 * 100 = 7.000000000000001
0.14 * 100 = 14.000000000000001
0.55 * 100 = 55.00000000000001
0.56 * 100 = 56.00000000000001
0.57 * 100 = 56.99999999999999
0.58 * 100 = 57.99999999999999
任何人都知道保险箱做乘法的方法会产生正确的结果和正确的位数吗?
谢谢!
于2007年6月26日在comp.lang.javascript中写道 :
0.28 * 100 = 28.000000000000003
0.29 * 100 = 28.999999999999996
< http://www.jibbering.com/faq/#FAQ4_7>
-
Evertjan。
荷兰。
(请更改x''我的电子邮件中的点数)
9月26日下午2:51,Evertjan。 < exjxw.hannivo ... @ interxnl.netwrote:
于2007年6月26日在comp.lang.javascript中写道 :
0.28 * 100 = 28.000000000000003
0.29 * 100 = 28.999999999999996
< http://www.jibbering.com/faq/#FAQ4_7>
-
Evertjan。
荷兰。
(请将x''es更改为我的电子邮件地址中的点数)
最初我无法弄清楚如何使用4.6中的代码。我终于
意识到toFixed()原型被覆盖了,而我所有要做的就是使用它如下:
之前:
..29 * 100 = 28.999999999999996
之后:
(.29 * 100).toFixed( 0)= 29.(然后我将正则小数输出)
也许在常见问题中需要一个例子或解释?
谢谢!
于2007年6月26日在comp.lang.javascript中写道 :
9月26日下午2:51,Evertjan。 < exjxw.hannivo ... @interxnl.netwrote:
>写于2007年9月26日的comp.lang.javascript :
0.28 * 100 = 28.000000000000003
0.29 * 100 = 28.999999999999996
< http://www.jibbering.com/faq/#FAQ4_7>
[请不要引用usenet上的签名,
任何体面的新闻阅读器都会自动跳过这些签名]
最初我无法弄清楚如何使用4.6中的代码。我终于
意识到toFixed()原型正在被覆盖,而我所有要做的就是用
来做如下操作:
不,默认的toFixed(n)被覆盖,因为它有一个错误[在IE中?]
之前:
.29 * 100 = 28.999999999999996
之后:
(.29 * 100).toFixed(0)= 29.(然后我正则表示小数除外)
也许在常见问题中需要一个例子或解释?
4.6间接声明toFixed(n)需要n> 0
这会节省你的一天吗?>
提醒(+(。29 * 100).toFixed(0));
[看,没有正则表达式]
-
Evertjan。
荷兰。
(请在我的电子邮件地址中将x'变为点数)
Hi,
I''m building an IE-centric portal for an intranet so I''ve only had to
develop for IE 6+
My version is: 6.00290.2180
Here''s what I''m seeing:
0.25 * 100 = 25
0.26 * 100 = 26
0.27 * 100 = 27
ok so far....
0.28 * 100 = 28.000000000000003
0.29 * 100 = 28.999999999999996
Not what I expected.
curiously, 0.299 yields what I''d expect, 29.9
Also, 0.299 * 1000 = 299, which is correct!
I iterated from 0.01 to 0.99 and these other combinations produce a
similar output:
0.07 * 100 = 7.000000000000001
0.14 * 100 = 14.000000000000001
0.55 * 100 = 55.00000000000001
0.56 * 100 = 56.00000000000001
0.57 * 100 = 56.99999999999999
0.58 * 100 = 57.99999999999999
Anyone know of a safe way of doing multiplication which will produce
the correct result and the right number of digits?
Thanks!
wrote on 26 sep 2007 in comp.lang.javascript:
0.28 * 100 = 28.000000000000003
0.29 * 100 = 28.999999999999996
<http://www.jibbering.com/faq/#FAQ4_7>
--
Evertjan.
The Netherlands.
(Please change the x''es to dots in my emailaddress)
On Sep 26, 2:51 pm, "Evertjan." <exjxw.hannivo...@interxnl.netwrote:wrote on 26 sep 2007 in comp.lang.javascript:
0.28 * 100 = 28.000000000000003
0.29 * 100 = 28.999999999999996
<http://www.jibbering.com/faq/#FAQ4_7>
--
Evertjan.
The Netherlands.
(Please change the x''es to dots in my emailaddress)
Initially I couldn''t figure out how to use the code in 4.6. I finally
realized that the toFixed() protype was being overriden and all I had
to do was use it as follows:
before:
..29 * 100 = 28.999999999999996
after:
(.29 * 100).toFixed(0) = 29. (then I regex the decimal out)
Perhaps an example or an explanation is needed in the faq?
thanks!
wrote on 26 sep 2007 in comp.lang.javascript:
On Sep 26, 2:51 pm, "Evertjan." <exjxw.hannivo...@interxnl.netwrote:> wrote on 26 sep 2007 in comp.lang.javascript:
0.28 * 100 = 28.000000000000003
0.29 * 100 = 28.999999999999996
<http://www.jibbering.com/faq/#FAQ4_7>
[please do not quote signatures on usenet,
any decent newsreader will skip those for you automagically]
Initially I couldn''t figure out how to use the code in 4.6. I finally
realized that the toFixed() protype was being overriden and all I had
to do was use it as follows:No, the default toFixed(n) was overridden, as it has a bug [in IE?]
before:
.29 * 100 = 28.999999999999996
after:
(.29 * 100).toFixed(0) = 29. (then I regex the decimal out)
Perhaps an example or an explanation is needed in the faq?4.6 indirectly states that that toFixed(n) needs n>0
Will this save your day?
alert( +(.29 * 100).toFixed(0) );
[Look, no Regex]
--
Evertjan.
The Netherlands.
(Please change the x''es to dots in my emailaddress)
这篇关于奇怪的行为,乘以小数(IE)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!