Home > front end >  Wonderful work, why the two Numbers multiplied, it is always a decimal point???????
Wonderful work, why the two Numbers multiplied, it is always a decimal point???????

Time:10-03

 

<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>








=& lt; Input type="text" name="xinghao_5 []" id="xinghao_5_1" value="" & gt;






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 problems
https://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 high

CodePudding 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 enough

CodePudding 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