Convert string into Double or Integer


#1

Convert.ToDouble(Time)*Convert.ToDouble(strOutPrice)

I’m trying to assign variable Total = Time (e.g. 11.234453 )x srtOutPrice ( e.g. 30)

I’m getting a conversion error


#2

Hi @Giovany,

Use this code
Total =Convert.ToDouble(Time)*Convert.ToDouble(strOutPrice)

you can’t multiply with string

Regards,
Arivu


#3

Hi @Giovany,

You can also store the Time and srtOutPrice variables as GenericValue types. These convert to proper number types when multiplication is performed.

Try making the variables of type GenericValue and then you can perform the multiplication without casting.


#4


still having trouble with the annotation
both variable are genericValues


#5

Hi @pvilleroy,

@Giovany,

If you are using Generic value if it will through the error when the value is null or empty.
So better to Convert it.

Regards,
Arivu


#6

Hi @Giovany,

If you are using Generic Value no need to convert to Double. if suppose Empty value it will through the error.make sure the value should not be empty or null.

if its an non empty field you use Generic Value.

Always better to use specific data type to avoid complexity

Regards,
Arivu


#7

@Giovany I agree with what @arivu96 says but if you know your variable will not be null, you can continue with GenericValue. Just make Total also a GenericValue in your screen above and there’s no need to convert. (sorry I can’t upload a .xaml until my profile has more points)


#8

I get the message somehow that I cannot multiply a string with a double


#9

Hi @pvilleroy,

@Giovany
Always better to use specific data type to avoid complexity

because may be empty/null value also it will come based on the scenario.

Regards,
Arivu


#10

Then in your case you will need to convert and use proper data types.


#11

Hi, @arivu96
I have Datatable with Column Type Double
Now using get row item i am populating that column but sometimes the column value will be empty so it throws an error that can cast null to double.
Please suggest best possible way


#12

DT1.Compute(“sum([#Amount])”,“Agent=’” & row(0).ToString & “’”)

I am working on this and unable to resolve the error as it is giving "Invalid usage of aggregate function sum() and type: object.

It is working when i using a build in datatable in studio but not when i am reading the data from excel.

Please suggest

Thanks