We want to modify the display format of a page's data, which requires two steps:
1. In JS through $ ('. Class1. Class2 Li:eq (2) Span.value '). Text (). Trim (); A similar statement gets the contents of the data.
2. Modify the data to the desired format. (eg:data=10 ==> 9+1)
If we get the data value is an integer, then no problem, things will go well, as expected results.
But if you take a decimal, the problem comes.
What is this for?
A: This is related to the data structure, the integer type automatically converted to positive type calculation, decimal type directly into the double type calculation, this is in memory operation must be so, you should know that the computer only know 0 and 1 bar, specifically the floating point accuracy problem, float accurate to the decimal point after the 7-bit double Accurate to 15 digits after the decimal point.
Knowing the cause of the problem, we just need to do a simple answer to the reserved decimal number operation, namely:
Data.tofixed (2);
The number of decimal digits is in the parentheses.
A long list of decimal places appears in JavaScript decimal subtraction