# Double.TryParse(InputValue,0) explanation

I am unable to understand what that (0) stands for within double.TryParse brackets.

@Vidya_Srinivasan - its a signature of the
Double.TryParse(input string , output double).

5 Likes

This doesn’t answer it for me. Perhaps you can elaborate. The .NET link you provided specifies that the second argument (double) TryParse(String, Double) has to be variable and gives out an error when set to 0.

TryParse only verifies if the input is a valid string containing double value. A TRUE means it is valid and FALSE means otherwise.
For example,
var_double double

double.TryParse( “12.34”, var_double) will return TRUE
double.TryParse( “12.34a”, var_double) will return FALSE

After evaluating the outcome you should then do the actual “parse” to get the value. Thus, if
strVAlue=“12.34” then the following code evaluates if the outcome is true and if yes, then converts the string value into double and stores it into a double variable. If false, then it prints a message:

if double.TryParse( strValue, var_double ) then (…do the parse)
var_double = double.Parse(strValue)
write line (strVAlue+" IS a double. var_double = “+var_double.ToString)
else
write line (strVAlue+” is NOT a double")

Hope this helps.

1 Like

That is not quite accurate. Double.TryParse is basically Double.Parse but wrapped in a Try-Catch.

Double.TryParse performs the conversion as well as returns TRUE or FALSE based on the results of the conversion. There is no need to redo the conversion using Parse. The second parameter is to hold the converted value.

For the OP, I would wager that UiPath academy is only trying to determine if the string value being converted is a double precision number. The 0 signifies a null value and thus disregards the converted value.

3 Likes

My project is set to VB and when I try the following:

Double.TryParse(“1.234”,Dbl_Amount)

The second argument (Dbl_Amount) is not modified in any way (e.g., if you assign it -99 first, it’s still -99 after the call). I didn’t get any different result with the C# version either.

It would seem that TryParse only returns the boolean function value and does not pass back the converted amount in the second argument.

If I’ve missed something here, please elaborate on how to both test the conversion and get the converted amount in the same call.

1 Like

Hi @John21042,

Welcome to the community!

In my opinion, the best way to use the TryParse method is through the invoke Method activity…

Variables:

Code: Invoke method’s properties:

Then, you are able to get both results (boolean and double)  Hope it helps Gustavo,
Thank you very much!

1 Like