07-26-2017 07:59 AM
I have noticed that the expression language version of the toFixed function rounds up on “5” but the Javascript version in web coding does not. Is this intentional? I did some research and maybe the SnapLogic version is using the Java version: .setScale(2, BigDecimal.ROUND_HALF_UP) for example.
10-03-2017 03:35 PM
Your research is correct, we are using setScale() with ROUND_HALF_UP.
As to the rounding behavior, web browsers seem to round up on ‘5’ in some cases as well. If you try toFixed() on the value ‘2.35’, it will return 2.4 in Chrome and FireFox. I’m not sure what causes the difference at the moment, but it might be due to the differences between using floating point numbers and BigDecimals. The BigDecimals will be more accurate in their results since floating point is more of an approximation.
10-03-2017 04:08 PM
or you can use this in the mapper
Math.trunc(($[FIELD]++0.005)*100)/100