isFloat and isInteger in javascript
解決的方法可以使用下列函數來檢查上isFloat和isInteger
function isFloat(n) {
return n === +n && n !== (n|0);
}
function isInteger(n) {
return n === +n && n === (n|0);
}
Demo
See the Pen How do check that a number is a float or integer in Javascript by Leon Cheng (@jq153387) on CodePen.