Good morning!
I have to implement a rounding rule in JavaScript following the ABNT NBR 5891: 2014 rule. . I tried to use only the existing functions like Math.round, Math.trunc, Math.floor, Math.ceil, but none gave 100%, the closest was Math.round.
The rule is as follows:
In the examples below we are applying the ABNT rule rounding up to 2 decimal places. Notice that 0 is considered even.
EX: [0.342, 0.346, 0.3452, 0.3450, 0.332, 0.336, 0.3352, 0.3350, 0.3050, 0.3150]
By the rule: [0.34, 0.35, 0.35, 0.34, 0.33, 0.34, 0.34, 0.34, 0.3, 0.32] , 0.35 , 0.35, 0.33 , 0.34 / strong>, 0.34 , 0.34 , 0.31, 0.32 , 0.33 , 0.33, 0.33, 0.33, 0.3 strong>, 0.31]
0.33, 0.33, 0.33, 0.3 , 0.33 , 0.33 strong>, 0.31] , 0.35 , 0.35 , 0.35, 0.34, 0.34 0.34 , 0.31, 0.32What would be the best way to adapt these rules in JavaScript?