PFB問題を示すサンプルコードスニペット:Javascriptの浮動小数点数加算
var x=0.323;
var cumulativeVal = 0;
for(i=0;i<30;i++){
cumulativeVal = cumulativeVal + x;
console.log(cumulativeVal);
}
上記計算の結果は
0.323
0.646
0.9690000000000001
1.292
1.615....
4.845000000000001
5.168000000000001
5.491000000000001
5.814000000000002....
9.690000000000007
余分進値が追加取得されることに注意してくださいです。私はこれがjavascriptの値の精度と関係があることを理解しています。しかし、誰も説明することができますか?
フロートがどのように格納されるかについての良い答えは、http://stackoverflow.com/questions/1907114/integers-and-float-precisionを参照してください。 – zrvan
[JavaScriptの数学は壊れていますか?](http://stackoverflow.com/questions/588004/is-javascripts-math-broken) –