Trouble using Cdbl and calculating difference

Hi.
I read a range table in excel, which fill the values found in SAP.
Then it calculates the difference between what it was already on the excel file and what it got from SAP.
When reading the value, in a for each row activity, I save the value using:

CDbl(CurrentRow("Price in SAP")) - CDbl(CurrentRow("Price"))

But the result has several decimals. Visually it looks like it’s ok, but internally I don’t feel sure.
ex.
Second row the difference between 5.40-5.41 = -.01; but why UiPath calculated as -0.0099999999979 instead?

image

Hi @JavRR

You can give a try this in order to get 2 dec if you want

Math.Round(CDbl(CurrentRow("Price in SAP")) - CDbl(CurrentRow("Price")), 2)

Regards

1 Like

You have to put .ToString onto the end of each CurrentRow:

CDbl(CurrentRow("Price in SAP").ToString) - CDbl(CurrentRow("Price").ToString)

If the columns are already double, then you don’t need to CDbl them nor use the .ToString

As for why the result is coming out the way it does, what are the values of Price and Price in SAP? Just like Difference is rounded, those other two values may also be rounded.

I solved my issue!
instead of using Cdbl, I used Cdec

CDec(CurrentRow("Price in SAP")) - CDec(CurrentRow("Price"))

The difference is what I expected. And everything is fine.
Thanks everybody. And also Chat GPT which helped me hahaha

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