javascript-number-toprecision

#toPrecision()方法 了解 JavaScript 的 toPrecision() 方法的所有内容 该方法返回一个表示特定精度的数值的字符串: new Number(21.2).toPrecision(0) // 出错!参数必须大于 0 new Number(21.2).toPrecision(1) // 2e+1(= 2 \* 10^1 = 2) new Number(21.2).toPrecision(2) // 21 new Number(21.2).toPrecision(3) // 21.2 new Number(21.2).toPrecision(4) // 21.20 new Number(21.2).toPrecision(5) // 21.200