1. tofixed Method
The ToFixed () method rounds numbers to a number that specifies the number of decimal digits. For example, if the data Num is reserved for 2 decimal places, it is represented as:toFixed (Num), but its rounding rules differ from those in mathematics, using banker rounding rules, bankers rounding: the so-called banker rounding method, Its essence is a four-house six into the five-take (also known as the four-six into the five left double) method. the specific rules are as follows:
In short, it is: four six into five considerations, five after non-zero into one, five after the zero look at parity, five ago for I should shed, five before for odd to go into one.
It is clear that this rule does not conform to the way we normally deal with data. To solve this problem, you can customize the implementation using the Math.Round method to specify how many bits of data are reserved for processing.
2. Round method
The round () method rounds a number to the nearest integer. For example:math.round (x) is the integer that takes x nearest to it. The method of trade-offs uses the method of rounding, which conforms to the rules of choice in mathematics. The processing of decimals is not so convenient, but can be customized according to different requirements.
For example, for X to preserve two-bit decimals, you can use Math.Round (x * 100)/100 for processing.
JS processing data rounding, tofixed and round difference