Math Functionality of Outsystems to round

Hai,

I am used round functionality, If I directly assign the expression of value Round(3.7) correct answer is displayed Ans 4. But If I using the local variable(Number) assignment Number=3.7,then I assigned the expression of value Round(Number) answer is not displayed correctly. Ans 3. Anyone can help me pls  Regards,

Jeyasri R

Hi Jeyasri

Please check the datatype of the variable (Number). I believe you are declaring it as an Integer, so the variable would store the value 3 only, so rounding or no rounding, you will get the answer as 3.

If you change the data type to Decimal, you will achieve what you are looking for.

Regards

I got 4.

mydecimal = round(3.7)

Check what data type is your variable?  In above it is decimal.

Amal Raj wrote:

Hi Jeyasri

Please check the datatype of the variable (Number). I believe you are declaring it as an Integer, so the variable would store the value 3 only, so rounding or no rounding, you will get the answer as 3.

If you change the data type to Decimal, you will achieve what you are looking for.

Regards

Thanks Amal

Behavioral wrote:

I got 4.

mydecimal = round(3.7)

Check what data type is your variable?  In above it is decimal.

Integer datatype..I changed the decimal datatype.I also got 4.It is work correctly, Thanks for ur reply

Amal Raj wrote:

Hi Jeyasri

Please check the datatype of the variable (Number). I believe you are declaring it as an Integer, so the variable would store the value 3 only, so rounding or no rounding, you will get the answer as 3.

If you change the data type to Decimal, you will achieve what you are looking for.

Regards

Hai Amal

I need another clarification. I have to set the odd number .5 for example Round(11.5) correct answer is displayed Ans 12. but If I am set the even number .5 for example Round(12.5) I got 12. Actually correct answer is 13 right.Can u pls help me.

Thanks,

Jeyasri R

Behavioral wrote:

I got 4.

mydecimal = round(3.7)

Check what data type is your variable?  In above it is decimal.

Hai

I need another clarification. I have to set the odd number .5 for example Round(11.5) correct answer is displayed Ans 12. but If I am set the even number .5 for example Round(12.5) I got 12. Actually correct answer is 13 right.Can u pls help me

Thanks,

Jeyasri R

Solution

QUoted from this document: https://success.outsystems.com/Documentation/10/Reference/OutSystems_Language/Logic/Built-in_Functions/Math#Trunc

In expressions in client-side and server-side logic, applies the method round half to even (rounds to the nearest integer, 0.5 rounds to the nearest even integer).

So, if it is exactly 0.5, it will be rounded to EVEN number. 12.5 will be 12 (12 is even, 13 is odd); 13.5 will be 14 (14 is even, 13 is odd), etc.

to round up, just use expression like this:

Round(If(x-Trunc(x)=0.5, x + 0.1, x)) where x is a variable that is assigned your value, like 12.5.

May this helps.

regards

Solution