JS pit in toFixed

ToFixed had always thought that the method of rounding, some time later that there is a five toFixed off and six. ToFixed know that today is called dual method of rounding banker.

What is a four banker's rounding: Baidu says so:
for many of the approximate number of digits, when the effective number of bits is determined, the excess number should lay down behind, leaving only the last one significant figure, which species rounding rules (rounding) is "four banker's rounding", i.e. "into 4 5 6 Minato round even" where "four" refers ≤4 is discarded, "six" refers to the time ≥6 into the "five" refers to a set according to the number after 5, when the several 5, 5 into a rounded; when no significant digits after 5, two cases need speaking: an odd number before ①5, homes 5 into 1; ②5 front is even, rounded 5 does not enter. (0 is an even number)

However, will find in the actual operation, when obtained by the examples of the absence of significant digits before the decimal point, before the number is 5 times 1 and 2, does not follow this rule. If significant figures exist, continue to follow the rules.

 

If there is an error, please comment treatise

Guess you like

Origin www.cnblogs.com/LeoXnote/p/12161171.html