Skip to content

Commit

Permalink
fix(types): Fixed FloatType constructor, change precision validator
Browse files Browse the repository at this point in the history
  • Loading branch information
CheerlessCloud committed Aug 13, 2017
1 parent fe329b4 commit a0b032f
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/types/float.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
}
}
Expand Down

0 comments on commit a0b032f

Please sign in to comment.