Appearance
数字
JavaScript 对大数字的支持有限。
123456789_123456789123456789123456780查看类型。
typeof 123
typeof 1.5
typeof 123n'number'
'number'
'bigint'加法。
1 + 2
0.1 + 0.23
0.30000000000000004减法。
7 - 2
0.7 - 0.25
0.49999999999999994乘法。
3 * 4
0.3 * 0.412
0.12除法。
8 / 2
7 / 2
0.8 / 0.24
3.5
4取整。
Number.parseInt(8 / 2, 10)
Number.parseInt(7 / 2, 10)
parseInt(8 / 2, 10)
parseInt(7 / 2, 10)4
3
4
3向下取整。
Math.floor(8 / 2)
Math.floor(7 / 2)4
3向上取整。
Math.ceil(8 / 2)
Math.ceil(7 / 2)4
4舍入。
Math.round(2.5)3Number.parseInt() 等效于全局的 parseInt() ,以便模块化。 Number.parseFloat() 等效于全局的 parseFloat() 。
取余。
8 % 2
7 % 20
1幂次。
2 ** 38