Can't convert currency Culture Info

Hi,

I have a string variable with value “1.000,00”. I want to convert this string to a double value in the pt-pt format. I’ve tried the following code:

Decimal.Parse(“1.000,00”, CultureInfo.CreateSpecificCulture(“pt-pt”))

When I run the code, it always returns an error!
Can you find what is wrong?

Hi @CarlosSousa

Welcome to our UiPath Forum! :slight_smile:

What is the error that you are getting?

The error is: “Assign TEMP txtMontanteReduzir_double: Input string was not in a correct format.”

The desired output is 1000,00

Looks like you will need to work on your CultureInfo a bit. See here:

  1. First initialize your CultureInfo variable:
    nfi = new CultureInfo("pt-pt")
    It should be of type:

  2. Then, assign these:

    nfi.NumberFormat.NumberGroupSeparator = "."
    nfi.NumberFormat.NumberDecimalSeparator = ","
    
    
  3. Finally, do your conversion:

    Decimal.Parse("1.000,00", nfi).ToString
    

    It returns:
    image

Here it displayed it as 1000.00, but that can be fixed by adding your culture to the ToString of the Write Line:

Decimal.Parse("1.000,00", nfi).ToString(new CultureInfo("pt-pt"))

image

4 Likes

Thank you very much! :slight_smile:
Now it’s working perfectly!

1 Like

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