Round a value

Hi Team,

I am trying to round up an amount which is not working correctly. I am using
Math.Ceiling()

48,743.98 - Output coming correctly as 48,744
48,743.50 - showing wrong result as 48743 instead of 48,744
48,743.10 - showing wrong result as 48743 instead of 48,744
621639.10 - wrong result as 6,21,639 instead of 6,21,640
how to fix this ?

Hi,

You can use Math.Round

1 Like

@Robotics - Math.Ceiling will ceil to the upper number even for a small decimal value.
To fix this one - use Math.Round - it will round to the next upper number based on 50%.

2 Likes

Still i am getting the same result only. Below is my code

Variable : SettlementAmount(String) = 6,21,639.10
Math.Round((Cint(SettlementAmount).ToString))
Storing result in Variable : SettlementAmount(String)

Result : 6,21,639
Expected : 6,21,640
Let me know what i need to change here

1 Like

You should provide a Decimal or a Double to Math.Round:

Math.Round(Convert.ToDecimal(SettlementAmount))

And I just saw I misread your opening post, sorry…:

Math.Ceil(Convert.ToDecimal(SettlementAmount))

When using CInt, you already rounding the original value: you were trying to apply Math.Ceil to an integer.

1 Like

Yes its working as expected, thanks a lot…