Datatable (string type) convert to double type

Excuse me, I want to try the result of output datatable (string type) convert to double type, because I want to put it in the if condition, but it occurs error…anyone know know how to solve it?

1 Like

What is the variable res? Is it a single value, a row or the entire data table? If it is a single value try using convert.toDouble(res.toString). If it is a row, you will need to specify which column of the row you wish to convert. If it is a data table you will need to specify both the row and the column you wish to convert.

1 Like

The res is that I use sql query “COUNT(*)” to count the amount of rows…I think it’s a single value, but I’ve tried convert.toDouble(res.toString) just now, but it doesn’t work😭

1 Like

Ahh I see ok. Hmm interesting, what type of variable is res being stored as? Is it just a string or is it being stored as something else?

1 Like

It’s a string

Oh I think I see the issue! You are assigning it back to the same variable, which is set as type string. You are trying to insert a double type into a string type. Try creating a new variable of type double and, using either of the formats, do the same assign but to the variable of type double.

1 Like

OH YESSSS IT WORKED!!! FINALLY :sob::sob: Thank you for your help and thanks for you patient :sparkling_heart::sparkling_heart: You’re the most kind-hearted person I’ve ever met :+1::+1::bowing_woman::bowing_woman:

1 Like


Sorry again… but when I run it, it occurs this…:fearful:

No problem! Try writing the string res to console using a writeline/log activity before you try changing the variable to double and see what the string actually contains. Depending on that, you may need to trim it or if it contains other symbols besides numbers and a decimal point, use regex to extract the numerical value.

1 Like

Wait…I found that it’s not a single value, it’s a row…OMG😵

1 Like

Oh! That would make sense. If you wanted only the number from that string you could do the following using regex:

This should return the number only and convert it to a double value (you don’t need to assign the default value in the variables, I only included that for testing)

If there are any other issues let me know!

1 Like

Thank you sooooo much :exclamation::exclamation::exclamation: You solved it :exclamation::exclamation::exclamation: You’re so knowledgeable and brilliant :100::heart_eyes:

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