Y006-字符串转为数字
parseInt
转为 整数
let num = parseInt('1000');
let num1 = +'1000'
let num2 = '1000' * 1
转为浮点数
、舍入数字时 Math.floor 的简写 你可以使用 ~~ 运算符,而不是使用 Math.floor() 函数来向下舍入数字:
// LONG FORM Math.floor(5.25) // -> 5.0
// SHORTHAND ~~5.25 // -> 5.0
转为 整数
let num = parseInt('1000');
let num1 = +'1000'
let num2 = '1000' * 1
转为浮点数
、舍入数字时 Math.floor 的简写 你可以使用 ~~ 运算符,而不是使用 Math.floor() 函数来向下舍入数字:
// LONG FORM Math.floor(5.25) // -> 5.0
// SHORTHAND ~~5.25 // -> 5.0