Bug on simple rounding
The issues section is used only for bug reports. Please use the Discussions section to ask questions and share ideas and suggestions.
Describe the bug I use this library for simple rounding of currency values. Below, I want to convert 0.145 € to cents.
To Reproduce round(0.145*100) returns 14, which should be actually 15 round(evaluate('0.145 * 100')) returns also 14, which is wrong round(14.5) returns 15, which is correct
Thanks for reporting, we should look into that! Most of the functions like equal, larger, ceil, fix do use a nearlyEqual check internally to handle round off errors like 0.145*100 = 14.499999999999998, but it looks like the function round doesn't.
@josdejong I wanted to take this this issue.
Thanks @rakheesingh! Please let me know when you need help (I haven't looked into this and I'm not sure what is needed to fix it).
Hello @josdejong! Wanted to know if the issue is still open? Would love to give it a try!
adding an epsilon fixes it:
...
// to prevent this error, add an epsilon
const epsilon = 1e-12;
return round(number + epsilon, decimals);
The issue is still open, thanks @developer-diganta for wanting to look into it. Help would be welcome.
Fixed now in v12.4.0 via #3136.