Round function behaviour
Question

Round function is not giving expected result

Round(24.805, 2)

Expected: 24.81

Result: 24.80

mvp_badge
MVP

Hi Lapor,

Round uses the standard .NET rounding, which is round to nearest even. So 805 gets rounded to 80, while 815 would be rounded to 82 (and so would 825).

Hello Lapor,

I hope you are doing well.

you can  use javascript toFixed() to achieve Your requirement. Please check this fiddle.

http://jsfiddle.net/VsLp6/



 And the Round action rounds to the nearest "even" integer in client and server actions as per the below documentation

https://success.outsystems.com/Documentation/11/Reference/OutSystems_Language/Logic/Built-in_Functions/Math#Round


There is a MathUtils forge component that provides an additional action available for server actions Math_RoundAwayFromZero(n: decimal)

Kind Regards,

Ajit kurane.

mvp_badge
MVP

Hi all,


Although you have find your answer, take also into account that are already some components in Forge that provide an extensive array of mathematical utility functions so you don't have to reinvent the wheel every time.

One of this components is Math Utils Reactive forge component which provides a client function to do the rounding away from 0:


Kind Regards,
João

Hi,

I hope you are great..

I had also mentioned it in my answer.

Kind Regards,

Ajit Kurane.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.