-
Notifications
You must be signed in to change notification settings - Fork 80
Description
Issue occurs with the following source for number=2.99 and divisibleBy=0.01, for other numbers works fine so far:
revalidator.validate({num: 2.99}, { properties: {num: {type: 'number', exclusiveMinimum: 0.98, exclusiveMaximum: 10, divisibleBy: 0.01, required: true, allowEmpty: false, messages: { allowEmpty: ' empty', exclusiveMinimum: ' > 0.98', exclusiveMaximum: ' < 10' } } } })
After investigation I found that an issue happens here
case 'number':
...
constrain('divisibleBy', value, function (a, e) {
var multiplier = Math.max((a - Math.floor(a)).toString().length - 2, (e - Math.floor(e)).toString().length - 2);
multiplier = multiplier > 0 ? Math.pow(10, multiplier) : 1;
console.log(555, (a * multiplier), (e * multiplier))
return (a * multiplier) % (e * multiplier) === 0 //<-----
//for num === 3.99:
});
break;
For 3.99 works fine:
(a * multiplier) // 3.99*10000000000000000 === 39900000000000000 /*divisible by*/ (e * multiplier) === 100000000000000
But for 2.99 - an error:
(a * multiplier) // 2.99*10000000000000000 === 29900000000000004 //<---!!! /*not divisible by*/ (e * multiplier) === 100000000000000
I'm using the latest Chrome 51.0.2704.103 (64-bit)