Fix for truncated instead of rounded results
Status: Beta
Brought to you by:
lmeyrick
https://sourceforge.net/p/bcmath-js/code/HEAD/tree/src/bcmath.js#l41
https://sourceforge.net/p/bcmath-js/code/HEAD/tree/src/bcmath.js#l79
https://sourceforge.net/p/bcmath-js/code/HEAD/tree/src/bcmath.js#l164
https://sourceforge.net/p/bcmath-js/code/HEAD/tree/src/bcmath.js#l201
In these lines, the script checks if the precision of the result is longer than wanted, and then just truncates the result which returns incorrect (because un-rounded) values.
The if blocks around these lines should instead be replaced by this one, which will round longer results correctly:
if (result.n_scale > scale) { result = libbcmath.round(result, scale); }