ES6数字操作

二进制/八进制

//声明二进制
let binary=0B010101;
console.log(binary);//21
//声明八进制
let octal=0o666;//第二个字母为o,大小写都可以
console.log(octal);//438

判断是否为数字

let isNum=11;
console.log(Number.isFinite(isNum));//true
console.log(Number.isFinite('eternity'));//false
console.log(Number.isFinite(NaN));//false
console.log(Number.isFinite(undefined));//false
console.log(Number.isFinite(null));//false

判断是否为NaN

console.log(Number.isNaN(NaN));//true

判断是否为整数

console.log(Number.isInteger(12));//true
console.log(Number.isInteger(12.1));//false

解析字符串为数字

let str='918.2';
console.log(Number.parseInt(str));//918
console.log(Number.parseFloat(str));//918.2

最大安全整数

let posiNum=Math.pow(2,53)-1;
let nagiNum=-Math.pow(2,53)-1;
console.log(posiNum);//9007199254740991
console.log(nagiNum);//-9007199254740991
console.log(Number.MAX_SAFE_INTEGER);//9007199254740991
console.log(Number.MIN_SAFE_INTEGER);//-9007199254740991
console.log(Number.MAX_VALUE);//1.7976931348623157e+308
console.log(Number.MIN_VALUE);//5e-324
let posiNumUnsafe=Math.pow(2,53)+1;
console.log(Number.isSafeInteger(posiNumUnsafe));//false
console.log(Number.isSafeInteger(posiNum));//true
posted @ 2020-02-07 11:40  未月廿三  阅读(245)  评论(0编辑  收藏  举报