Number.EPSILON 是 JavaScript 表示的最小精度
function equal(a, b){
if(Math.abs(a-b) < Number.EPSILON){
return true;
}else{
return false;
}
}
console.log(0.1 + 0.2 === 0.3);false
console.log(equal(0.1 + 0.2, 0.3))
二进制和八进制
let b = 0b1010;
let o = 0o777;
let d = 100;
let x = 0xff;
console.log(x);
Number.isFinite
console.log(Number.isNaN(123));
Number.parseInt Number.parseFloat字符串转整数
console.log(Number.parseInt('5211314love'));
console.log(Number.parseFloat('3.1415926神奇'));
Number.isInteger 判断一个数是否为整数
console.log(Number.isInteger(5));
console.log(Number.isInteger(2.5));
Math.trunc 将数字的小数部分抹掉
console.log(Math.trunc(3.5));
Math.sign 判断一个数到底是正数,负数,零
console.log(Math.sign(100));
console.log(Math.sign(0));
console.log(Math.sign(-20000));