//判断是否是整数
{
console.log('25',Number.isInteger(25));//true
console.log('25.0',Number.isInteger(25.0));//true 25.0=25 console.log('25.1',Number.isInteger(25.1));
console.log('25.1',Number.isInteger('25'));
}
//判断数是否在安全区间
{
console.log(Number.MAX_SAFE_INTEGER,Number.MIN_SAFE_INTEGER);
console.log('10',Number.isSafeInteger(10));
console.log('a',Number.isSafeInteger('a'));
}
//判断带小数的整数部分并返回
{
console.log(4.1,Math.trunc(4.1));//4
console.log(4.9,Math.trunc(4.9));//4
}
//判断正负数
{
console.log('-5',Math.sign(-5));//-1
console.log('0',Math.sign(0));//0
console.log('5',Math.sign(5));//1
console.log('50',Math.sign('50'));//1
console.log('foo',Math.sign('foo'));//NAN
}
//立方根
{
console.log('-1',Math.cbrt(-1));//-1
console.log('8',Math.cbrt(8));//2
}
网友评论