# Double

Hi guys,

can you help me with double variables? When my variable is 0 it throws error. However, I do a sum of two variables to check if the total is correct. So when one of them is zero I have to do try catch but still I dont know which one of them is 0.

Can you attach the workflow?

You might try using Convert.ToDouble when using the numbers.
like, CDbl(number) or I believe the other syntax is number.Convert.ToDouble

Thats exactly what I am using. I am storing the numbers in my DT and do the sum

Sum = Convert.ToDouble(DT.Compute(â€śsum([amounts])â€ť,""))

Is it is zero, it will throw an exception. Any ideas ?

My variables are amounts lets say from invoice. There can be plenty of them. ANd I have one row of invoice in one row of DT. So I go through rows and read the amounts if some conditions are met. Then I get for example 22.98, 33.44 etc. which must be double if I wanna do a sum, right? But when you do not fill anything into the DT it throws error when I do the sum which you can see above. Moreover, it is not possible to set the default value in the DT to be zero.

In the end I do this for three types of amounts. One which is taken into account, one which is not and special type. ON the invoice I have just total so I need to check the total sum of them.
Convert.ToDouble(DT1.Compute(â€śsum([amounts])â€ť,"")) + Convert.ToDouble(DT2.compuute(â€śsum([amounts])â€ť,"")) + Convert.ToDouble(DT3.Compute(â€śsum([amounts])â€ť,"")) cannot be in try catch because I dont know which of them is the null DT.

TO be more precise I have it as a condition in IF activity that total=sumofDT1+sumofDT2â€¦

The only solution I found so far is put if activity into try catch. Excepiton is another try catch with the same if but without one of the Sum of DT. In it is another excepitoon withou the amount from previous excepiton and the one which was omitted was added. I am looking for more elegant solution

Does the .Where work which allows you to add a condition?

Convert.ToDouble(DT1.Where(Function(x) x(â€śamountsâ€ť).ToString.Trim<>"").Compute(â€śsum([amounts])â€ť,""))

Sorry, I have not tested this and wasnâ€™t sure if the syntax is correct.

Not working:( Where is not a member of DT system

What is the validation errors you receive?

Thinking about it, you might need it to be like

Convert.ToDouble(DT1.AsEnumerable().Where(Function(x) x(â€śamountsâ€ť).ToString.Trim<>"").CopyToDataTable().Compute(â€śsum([amounts])â€ť,""))

Hope that helps better.

1 Like

Solved!!! Love!

Its throwing error. Inside a loop it says after several steps that The source conatins no DataRows. Any ideas why?

Hey @ClaytonM

How can i insert a double variable into excel?If i use write cell activity then it asks to convert it into string.

Hi @SHAISTA

I believe if you use an Excel Scope with Write Cell or Write Range, Excel handles the formatting. So, if you send a date or number in as a string Excel still automatically formats it by default. However, I could be wrong though.