 # Calculation with double

Hello!

I’m facing with a weird problem while working with decimals. I need to sum a column of a report that has decimal values. But I realized that uipath gives strange result when I try to sum x.00 value with -x.07 (0.929999999). And it’s happens only with .07

Any idea why? @sarikayaebru Are you doing any Extra Calculation part other than just taking the difference? Can you show the method that you used. If that is occurring Consistently and you want the Output to have only 2 decimal places then we can use Math.Round(yourSumValue,2)

I was using this in If activity

``````in_CompareDT.AsEnumerable().Sum(Function(row) cdbl(row.Item(in_BalanceColumnName))) = 0
``````

and it was working perfectly with decimals. But today it got false even if it was true. The result was -7.45058059692383E-09

Then I put the rows in a for each row activity and sum them one by one to see if a value comes in incorrect format. (sum = sum + cdbl(row.item(0))). It sums -74578741.07 and 79970356, gives the result 5391614.92999999.

After that I simply used 3 assigns which num1 = 1, num2 = -0.07 and sum = num1 + num2, the result was the image above.

For this I will use rounding but I wonder why it only happens while extracting 0.07.

@sarikayaebru Sometimes it might interpret a double result to a very large number of decimals since it has the capability as a double value, We Should use Rounding off of values if we need only upto specific decimals.

2 Likes

@sarikayaebru
about the explanation I agree to SupermanPunch
for Roundings have a look here: first line rounding the double
second line do the rounding for String Base

And respecting Locals see here: 1 Like

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