File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed
Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -108,16 +108,23 @@ Number.MIN_SAFE_INTEGER // -9007199254740991
108108
109109### Number.prototype.toFixed()
110110
111- ` toFixed ` 方法先将一个数转为指定位数的小数,然后返回这个小数对应的字符串。
111+ ` toFixed() ` 方法先将一个数转为指定位数的小数,然后返回这个小数对应的字符串。
112112
113113``` javascript
114114(10 ).toFixed (2 ) // "10.00"
11511510.005 .toFixed (2 ) // "10.01"
116116```
117117
118- 上面代码中,` 10 ` 和` 10.005 ` 转成2位小数, 其中` 10 ` 必须放在括号里,否则后面的点会被处理成小数点。
118+ 上面代码中,` 10 ` 和` 10.005 ` 先转成2位小数,然后转成字符串。 其中` 10 ` 必须放在括号里,否则后面的点会被处理成小数点。
119119
120- ` toFixed ` 方法的参数为小数位数,有效范围为0到20,超出这个范围将抛出 RangeError 错误。
120+ ` toFixed() ` 方法的参数为小数位数,有效范围为0到20,超出这个范围将抛出 RangeError 错误。
121+
122+ 由于浮点数的原因,小数` 5 ` 的四舍五入是不确定的,使用的时候必须小心。
123+
124+ ``` javascript
125+ (10.055 ).toFixed (2 ) // 10.05
126+ (10.005 ).toFixed (2 ) // 10.01
127+ ```
121128
122129### Number.prototype.toExponential()
123130
You can’t perform that action at this time.
0 commit comments