js判断有没有小数点
可以使用正则表达式来判断一个字符串是否包含小数点,如下所示:
function hasDecimal(num) {
return /\./.test(num);
}
console.log(hasDecimal("12.34")); // true
console.log(hasDecimal("1234")); // false
上面的 hasDecimal 函数接受一个字符串作为参数,然后使用正则表达式 /\.+/ 来匹配字符串中的小数点。如果字符串中包含小数点,返回 true,否则返回 false。
原文地址: https://www.cveoy.top/t/topic/eRP1 著作权归作者所有。请勿转载和采集!