首页 > 其他 > 详细

判断是否为整数 整数判断

时间:2016-01-28 15:12:57      阅读:231      评论:0      收藏:0      [点我收藏+]

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

判断是否为整数 整数判断

原文:http://www.cnblogs.com/chuangweili/p/5166276.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!