Menu

#5 Fix for truncated instead of rounded results

v1.0 (example)
open
nobody
None
5
2017-11-02
2017-11-02
Rob
No

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);
}

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.