Convert string to double variable with special characters?

Can we convert special characters string variable to double?

I have a string variable e.g “-” , Need to convert this into double for enter into excel output , Can someone guide me please. How to convert this ?

Thanks & Regards,
Jamuna T

Hey @jamunatj.

You can use Convert.ToDouble(strVar.Replace(“-”,“”))


Thanks for the response @Sanjit_Pal

I am trying to assign hyphen only in double variable but Here , I couldn’t assign the hyphen in double variable. How to handle this?

Jamuna T

Hi @jamunatj ,

Could you Provide an Example as to what would be the Input and what should be it’s Converted Double value ?

It would help us to understand your requirement better.

as mentioned a “-” is not representing a double value
Depending to your scenario you can check the business requirements.
So it can be the case that “-” can mean no value and no value can maybe expressed with 0
yourDoubleVar = If(strVal.Trim.Equals("-"), 0, CDbl(strVal.Trim)

1 Like
  1. use replace method,like “-”.Replace(“-”,“0”)
    2.use Set excel cell format or use ToString("f2") input to excel

This is utterly pointless. You’re converting it from string back to string.

Thanks for the response @supermanPunch
Kindly refer this file Main.xaml (7.0 KB)

I am extracting double variable value from pdf and assigned in then part , Here need to assign hyphen in the same variable at else part & no need to assign Zero or Empty if the string value not contains. Finally extracted value enter into the excel data.

Kindly guide me. how to handle this.

Thanks & Regards,
Jamuna T

1 Like

@jamunatj ,

In Addition to the workflow Provided, Could you provide the Input and the Expected Output ? A Sample like below :

Input = "1234"
Output = "1234-1"                //Just An Example, Provide the Output as per your logic

From the workflow we cannot deduce what should be the Output that you require or the Logic.

This means it will be a negative number, and when you output it with .ToString it will have the - because it’s a negative number.