.toFixed(2) function behaves differently than Javascript version

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.

1 Like

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.

1 Like

or you can use this in the mapper