diff --git a/src/types/float.js b/src/types/float.js index b0cffb7..dec6bbe 100644 --- a/src/types/float.js +++ b/src/types/float.js @@ -3,20 +3,17 @@ import NumberType from './number'; const { abs } = Math; class FloatType extends NumberType { - constructor(min, max, precision) { - super(min, max); + constructor({ min, max, precision = -1 } = {}) { + super({ min, max }); this.validators.push((val) => { if (precision < 0) { return true; } - const afterDot = String(abs(val)).split('.')[1]; + const afterDot = String(abs(val)).split('.')[1].length; - return !!( - (afterDot && afterDot.length >= precision) || - (!afterDot && precision === 0) - ); + return afterDot >= precision; }); } }