Fix rounding in toBeCloseTo

This commit is contained in:
Pierre Vanduynslager
2017-06-25 16:59:24 -04:00
parent 6aa069d586
commit c604012793
2 changed files with 28 additions and 1 deletions

View File

@@ -21,8 +21,9 @@ getJasmineRequireObj().toBeCloseTo = function() {
);
}
var pow = Math.pow(10, precision + 1);
return {
pass: Math.abs(expected - actual) < (Math.pow(10, -precision) / 2)
pass: +(Math.round(Math.abs(expected - actual) * pow) / pow).toFixed(precision + 1) <= (Math.pow(10, -precision) / 2)
};
}
};