<meta HTTP - equiv="Content - Language" Content="useful - cn" & gt;
Window. The onl oad=function () {
Var inputs=document. QuerySelectorAll (" input ^=xinghao_3_ [id], input ^=xinghao_4_ [id] ");
for(i=0; iInputs [I] onblur=function () {
Var n=this. Id. Slice (1);
Var add1=document. GetElementById (" xinghao_3_ "+ n). The value;
Var add2=document. GetElementById (" xinghao_4_ "+ n). The value;
Document. The getElementById (" xinghao_5_ "+ n). Value=https://bbs.csdn.net/topics/add1 * add2;
}
}
}
</script>
For example, 12000 x2. 55, its result always into: 30599.999999999996???
If the normal calculation is no decimal point, is equal to 30600 directly, how to fix the problem??
CodePudding user response:
The decimal precision problemshttps://www.jianshu.com/p/388f4053d2bb
Simple solution
(value=https://bbs.csdn.net/topics/parseFloat (add1 * add2). ToFixed (10))
CodePudding user response:
See you accuracy to keep to a few, js accuracy is not highCodePudding user response:
Can use bigNumber. Js (https://github.com/MikeMcl/bignumber.js), although there are a few small flaws, but deal with general data is enoughCodePudding user response:
Brother js multiplication is calculate by floating point must have the decimal; If you don't deal with you to the front desk to fiexd background; The best background processing- Related
- Links:
- CodePudding