JavaScript 检查数字是否为整数或者浮点数
检查是否为整数
function isInt(n) {
return typeof n === ‘number’ && n % 1 == 0;
}
// or ,this support ie3
function isInt(n) {
return typeof n === ‘number’ && parseFloat(n) == parseInt(n, 10) && !isNaN(n);
}
检查是否为浮点数
function isFloat (n) {
return n===+n && n!==(n|0);
}
