12
Views
4
Comments
Solved
Rounding off a number is not giving correct precision

Hi,

I am trying to round off a decimal number and if the last digit is 5 then its getting rounded off to the nearest even number. How can I fix this issue?


Thanks,

Shree

Rank: #1984
Solution

Hi,

I have tried with other expression also.. Thats also working..

Number is the decimal which you want to roundoff

Temp = Number * Power(10,Length(Number)-Length(Trunc(Number))-2)
Result = If(Temp - Trunc(Temp ) = 0.5, (Trunc(Temp )+1)/Power(10,Length(Number)-Length(Trunc(Number))-2),Round(Number,Length(Number)-Length(Trunc(Number))-2))

Rank: #56
Solution

Hi Shreelaskhmi,


While Outsystems rounding by default, applies the method round half to even (rounds to the nearest integer, 0.5 rounds to the nearest even integer), this function applies Round half up, i.e. rounds to the closest integer and in the case of .5 rounds up.

You can solve it using a function like in my OML in attachment and screenshot below:



More detail: check https://success.outsystems.com/Documentation/11/Reference/OutSystems_Language/Logic/Built-in_Functions/Math#Examples_5 and https://en.wikipedia.org/wiki/Rounding


Hope it helps.


Regards,
João

RoundUp.oml

Rank: #1984

Thank you João.. It worked :)

Hi Shree,

Can you share the expression you are using to round off the number? Is it client side or server side? 

Thanks, 

Nicholas

Rank: #56
Solution

Hi Shreelaskhmi,


While Outsystems rounding by default, applies the method round half to even (rounds to the nearest integer, 0.5 rounds to the nearest even integer), this function applies Round half up, i.e. rounds to the closest integer and in the case of .5 rounds up.

You can solve it using a function like in my OML in attachment and screenshot below:



More detail: check https://success.outsystems.com/Documentation/11/Reference/OutSystems_Language/Logic/Built-in_Functions/Math#Examples_5 and https://en.wikipedia.org/wiki/Rounding


Hope it helps.


Regards,
João

RoundUp.oml

Rank: #1984

Thank you João.. It worked :)

Rank: #1984
Solution

Hi,

I have tried with other expression also.. Thats also working..

Number is the decimal which you want to roundoff

Temp = Number * Power(10,Length(Number)-Length(Trunc(Number))-2)
Result = If(Temp - Trunc(Temp ) = 0.5, (Trunc(Temp )+1)/Power(10,Length(Number)-Length(Trunc(Number))-2),Round(Number,Length(Number)-Length(Trunc(Number))-2))