Convert from str to Double and multiply by -1

Hello all,

I am using regex to get an amount from an invoice. Assing activity: Value = System.Text.RegularExpressions.Regex.Match(file,"(?<=Importe solicitado a devolver )(\d|.|,)*").Value.ToString.

After that, I want to convert the variable Value to Val (Double), so I can multiply the amount by -1 and paste in an exce file.

The problem appears at assigning Val = Convert.ToDouble(Value). It appears this message: “The input string is not in the correct format.”.

Do you know how can I solve this issue?

PD: I have also tried Val = Double.Parse(Value).

Many thanks :slight_smile:

Hi @Angel_Llull,

What’s the format of Value ?

It is string

Yes, but can you provide a sample of the string, to see if there are things in the string that can’t be coverted

I am not sure if I understood what you would need. But if you are meaning an example of the amount, the amount is 609,39.

I use regex to get this amount, and then I need to multiply by -1.

Thanks :slight_smile:

Can you put in a message box the Value, so too see what the regex takes?

I would like to see if € or other characters appear in the string Value that you are going to convert

This is how appers:

image

Try this then:

Convert.ToDouble(Replace(Value,".",""))

If you get for some reason ain integer then you can try

Convert.ToDouble(Replace(Replace(Value,".",""),",","."))

This will change the format, if you version of UIPath use the . as a delimitor for decimal for some reason

@Angel_Llull
internally the Double is definining the decimal seperator with a dot and the group seperator with a comma (line2 in screenshot). That’s why the exception is raised

Local specific formatings can be handled with the cultureInfo (Line1 in screenshot)
grafik

4 Likes

Hello @Gabriele_Camilli

Using the replace the commas and dots dissapeard, and whole amount, without comma and dot is written in the excel .

I have used this:

Assign: Val = Convert.ToDouble(Valor, System.Globalization.CultureInfo.InstalledUICulture)

Write cell= (Val * -1).ToString(new CultureInfo(“es-ES”))

Doing that it worked.

Many thanks :slight_smile:

1 Like

Many thanks @ppr! :slight_smile:

It worked!

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