保留n位小数的正则

424 阅读1分钟

保留n位小数的正则:

	const FloatReg = ( n ) => {
    // 保留n位小数 
    const str  = `^((0\\.[0-9]{1,${n}})|([1-9]\\d*(\\.[0-9]{1,${n}})?))$`;
    return new RegExp( str );
}