Replies: 2 comments 2 replies
-
You could try to extend the functionality according to your needs. Maybe something like this. function bankersRounding(value) {
const roundedValue = math.round(value);
const remainder = value - math.floor(value);
if (math.equal(remainder, 0.5)) {
return math.floor(value) % 2 === 0 ? math.floor(value) : math.ceil(value);
}
return roundedValue;
}
math.import({ bankersRounding : bankersRounding}) |
Beta Was this translation helpful? Give feedback.
0 replies
-
If I'm not mistaken, the only difference with bankers rounding is rounding When you configure mathjs to use BigNumbers, you can utilize the rich rounding options of the library used for the bignumbers: decimal.js. math.config({ number: 'BigNumber'})
math.BigNumber.set({ rounding: math.BigNumber.ROUND_HALF_EVEN })
console.log(math.format(math.evaluate('round(0.5)'))) // 0
console.log(math.format(math.evaluate('round(0.225, 2)'))) // 0.22
console.log(math.format(math.evaluate('round(0.235, 2)'))) // 0.24 |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
There is no way to use other rounding method like banker's rounding, which is common in financial applications. Adding this feature would be great I think since this library has so many math functions that others libraries do not have. For now, I can only rely on another library like big.js. But functionalites are seems to be duplicate with this library.
Beta Was this translation helpful? Give feedback.
All reactions