fenzhi-utils
Version:
分值前端项目的js函数库
23 lines (22 loc) • 604 B
JavaScript
/**
* 是否可以转换成数字
* @param {*} n 检测类型
* @returns {boolean}
*/
/**
CustomIsNumeric(42); // true
CustomIsNumeric('42'); // true
CustomIsNumeric(' 42 '); // true
CustomIsNumeric('4.2'); // true
CustomIsNumeric('4,2'); // false
CustomIsNumeric(''); // false
CustomIsNumeric(' '); // false
CustomIsNumeric(null); // false
CustomIsNumeric(undefined); // false
CustomIsNumeric(NaN); // false
CustomIsNumeric(Infinity); // false
CustomIsNumeric(-Infinity); // false
*/
export function CustomIsNumeric(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
}