I have looked at the other topics yet I cannot find the solution.
I am simply trying to add two values from an excel file.
The values are of the type “1000” or “1000.5” if there are decimals. The problem is when using “Get row item” it stores the output as STRING type generic variable (eg. “debits”) in the case of “1000” and DOUBLE type generic variable (eg. credits) in the case of “1000.5”, when I try to add/subtract these two variables eg. balance = debits - credits, I get an error : you cannot subtract a system double from a system string
When I try to convert to double first using double.parse(debits.tostring) I once again receive an error:
input string was not in correct format (refer attached)
@Ellboy@HareeshMR please refer to the workflow I have tried both these methods but they throw out the same exception. It needs to convert the “Get row item” from its generic value which is either “1000” if no decimal or “1000.5” if there is decimal ie. if there is no decimal ie. in the case of “1000” it is as “1000” straight not as “1000.0” so what do you suggest I can store the “Get row item” variable as in order for me to add/subtract? OR if I store it as generic variables in their current format how do I properly convert to any type which can be added or subtracted be that decimal/double/etc.Main.xaml (15.4 KB) project.json (759 Bytes)
What I want to do is subtract to values after converting them to double, if you try assign another value eg. 2.5 to another variable eg. gen2 and then convert to double using your method and then try and subtract gen from gen2 it will not work, when using “Get row item”
Make sure you check that it’s a number before converting. If(IsNumeric(row(0)), CDbl(row(0)), 0)
or If(IsNumeric(row(0)), CDbl(row(0)), 0) - If(IsNumeric(row(0)), CDbl(row(0)), 0)
As another safe-guard, you can trim the value by changing row(0) to row(0).ToString.Trim
Also, try to avoid using Generic types. In my opinion, if the value is supposed to be a number, then use a Double or Integer type, and if it is a String use that type. If it can be either one, I use Object sometimes. A DataRow is an Object, which is why row(0) needs to be converted to your desired type before using the value.
I tried that it does not work exception says “cannot subtract a string from a system double” when trying to directly subtract a generic from a generic.
None of these methods are working let me try and break it down:
I have read values from an excel table, stored in to a DataTable variable.
The possible values in the columns [Debits] and [Credits] in the DataTable are of the type “0” or “0.0” (if there are decimals) or simply “” (ie. blank) if there is no values in the cells.
I then want to take the certain debits and subtract the certain credits which I am unable to do because these are different data formats but all are numbers.
What is the suggestion?