Round off to a decimal number

@adishjain

Variables:
VarAmount (Double) = 13706.505
RoundOffLimit (Int32) = 2

Activities:
Assign:

  • To: rounded_amount
  • Value: Math.Round(VarAmount, RoundOffLimit)

Write Line:

  • Text: rounded_amount.ToString

Hi @adishjain

Math.Round(VarAmount*RoundOfLimit, 2)

Ex:

i tried it but it is giving me 13706.50

@adishjain

Assign activity:
VarAmount = 13706.505
RoundOfLimit = 2

Assign activity:
VarAmount = Math.Ceiling(VarAmount * Math.Pow(10, RoundOfLimit)) / Math.Pow(10, RoundOfLimit)

1 Like

this can happen due the internal precision and as we do see the .505 is with the last 5 within the middle and let’s not flip to 51

your code is having only one decimal place, please try it with 3 decimal places. Like 123.325, then it should give as 123.33 in result

but Sir, it is business requirement

@adishjain did you try above one.

it is not a problem. Once we have understood the technical base we can take care of and fullfill the business requirement

1 Like

Hi @adishjain

Math.Ceiling(Var1 * Math.Pow(10, Round)) / Math.Pow(10, Round)

image

1 Like

Hi @adishjain

  1. Read the value of VarAmount from your data source or variable.
  2. Read the value of RoundOfLimit from your config file or variable. In your case, it’s 2.
  3. Use the Math.Round method to round VarAmount to the specified number of decimal places (RoundOfLimit).
    VarAmount = Math.Round(VarAmount, RoundOfLimit)
    VarAmount = Math.Round(13706.505, 2)

Hope it helps!!

@adishjain Try Above one it will give you desire value

You can try:
grafik

@adishjain

1 Like

it is giving me 13706.50

yes it is working sir, thankyou so much

it is working for me, thankyou

1 Like

@adishjain


we should also keep in mind that after a certain precision the portion is ignored:

grafik
grafik

Acrobatics like multiply / pow it by black Cat then divide it by hungry tiger is only touching some other values with a different precission. This can work in a scenario but also fail again within another case

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.