判断是否为整数 整数判断

1、取余数判断,整数除以1都为0

function isInteger(obj) {
    return typeof obj === 'number' && obj%1 === 0
}
 
2、使用Math.round、Math.ceil、Math.floor判断
function isInteger(obj) {
    return Math.floor(obj) === obj
}
 
3、ES6提供了Number.isInteger
 
 
 
parseInt(1000000000000000000000, 10) === 1000000000000000000000     //false

posted on 2016-01-28 14:57  迷茫小飞侠  阅读(492)  评论(0编辑  收藏  举报

导航