Today, I found Baidu and Mu. I checked Google and Mu. I asked my friend and told me that I had done it myself and finally got it. Haha
Everyone has noticed that, in fact, our law knows that it is wrong:
Note:
The function used to retain two decimal places in Javascript is tofixed (2)
However, when this function is combined with the "%" sign, it will be confused and will not be heard. Please refer to the following example for comparison:
Example 1:
VaR Ss = (parsefloat (AA [0])/parsefloat (AA [1]). tofixed (2 );
Alert (SS * 100 + "% ");
It is very likely that 54.5000000001% of the data will show this effect.
Example 2:
VaR Ss = (parsefloat (AA [0])/parsefloat (AA [1]) * 100;
Alert (ss. tofixed (2) + "% ");
Then, the result is what you want.
What are the causes of these two differences?
In fact, it's just the first person in the trap,
If we keep two decimal places and use the tofixed () method, multiply the number by 100, then the effect we don't want will appear.
If we multiply the value by 100 and use the tofixed () method to keep two decimal places, we will not get the effect we don't want!
I'm a cainiao. Please see me .... Haha