Double

code
studio

#1

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.


#2

Can you attach the workflow?


#3

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


#4

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 ?


#5

Please help me understand. What exactly are you trying to achive? And which are your 2 variables?


#6

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…


#7

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


#8

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.


#9

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


#10

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.


Error in storing double value in excel
#11

Solved!!! Love!


#12

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


#13

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.


#14

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.

So, just add .ToString on the end of your number.


#15

Yes you are correct. I did it