Individual RM not considered in additional constructor
saschbro opened this issue · comments
Hi and thanks a lot for this great library!
I wondered about the following behavior that contradicts the example from the doc's FAQ section. Shouldn't it be possible to set RM
individually on an additional constructor. Seems like Big's RM
is used when no rm
is set for methods like toFixed
and round
.
const Big = require('big.js');
// additional constructor
const X = Big();
X.NE = -10;
X.RM = 0;
const x1 = X('7.55');
console.log(x1.toFixed(1)); // expected 7.5 but is 7.6?
console.log(x1.toFixed(1, 0)); // correct
const x2 = X('0.00000000888');
console.log(x2.toString()); // correct
// main constructor
Big.NE = -10;
Big.RM = 0;
const b1 = Big('7.55');
console.log(b1.toFixed(1)); // correct (7.5)
const b2 = Big('0.00000000888');
console.log(b2.toString()); // correct
// additional constructor again
console.log(x1.toFixed(1)); // now also correct (7.5) after we set Big.RM
Also I got a bit confused while trying around because of the docs for RM
. Isn't it Big.roundDown
instead of Big.roundUp
and vice versa in the first column of the table?
😲
Fixed in v6.1.1. Thanks a lot!
The bug was introduced in v6.0.0 when I refactored a PR that added a rounding mode parameter to toFixed
etc.
And thanks also for noticing the mistake in the rounding mode documentation. How could that happen? I blame git.
Muchas gracias.
Great! Thanks a lot too! Happy to hear that I could help!