检查一个字符串是否符合浮点数格式 请注意,整型不属于浮点数。若要包含整型,请使用实数isReal
import { isFloat } from "check-string"; ... let str = '12.53'; let result = isFloat(str, { canNull: true, max: 500, min: 0, decimals: 2 }); //str可以为null,最大500,最小0,小数点后最多2位小数 if (!result.success) { console.log(result.error.code); // 输出错误编号 console.log(result.error.cn); // 输出错中文错误 console.log(result.error.en); // 输出错英文错误 }
被检查的字符串