# Convert from str to Int and multiply by *-1

Hello all

I am facing a issue with converting a variable from string to integer. The robot reads a range from excel and then i assign each column to a variable: row(x).ToString. One column (“Amount”) is composed by amounts. So the robot reads this amounts as string and I do the following steps:

Assign activity --> Value = Cint(“Amount”)

Write cell act --> Value * -1

Doing that, i get this message error in the assign activity: Asignar: Conversion from string “55.358,61” to type ‘Integer’ is not valid.

So, how could i do it to convert to integer and multiply? Because I don’t know if Value * -1 is correct.

Many thanks!

The error must be in the format 55.358,61
Bot knows .(Dot) as decimal separator and having ,(Comma) after that is invalid. hence the error

1 Like

Hi @Angel_Llull,

You are truncating the number this way

The conversion should be to Decimal. Also you should eliminate the point in the amount, i think i will give you problems

The *-1 on the other end works fine

If you need any suggestion on the implementation, ask

1 Like

Hey @Angel_Llull

First of all we need to convert your amount to a double and not an integer (integers are only whole numbers, while doubles can hold decimal values).

Your culture has reversed thousand seperator and decimal. That is UiPath will need it in the following format: 55,358.61. My culture is Danish and I face the same “problem” as you.

Here is, how we solve it:

We have two variables: Amount (String) = “55.358,61” and Value (Double)

First we convert our Amount to a double and “tell” UiPath, that we use another culture in our UI.
Assign: Value = Convert.ToDouble(Amount, system.Globalization.CultureInfo.InstalledUICulture)

Then we can do our calculation:
(Value*-1).ToString

Attached is the xaml for you: Main.xaml (4.2 KB)

Let me know, if that helps

Kind regards
Anders Jensen

1 Like

@Angel_Llull
as @AndersJensen mentioned it is all about formats and Cultures.

With this following alternates you can take control on it:

first line: we can set the Culture which are to apply (I am forcing to spanish, but my locals are different)
second line: we can check if the value is parseable or not

Another option to take didicated control on it is using the Numberformat isolated:
Creation

Configuration:

nfi2.NumberDecimalSeparator
nfi2.NumberGroupSeparator
Usage:

find demo xaml here:
CustomDoubleParse.xaml (5.5 KB)

Ensure following that you can write shorter statements:

2 Likes

Hello @AndersJensen,

Now, in the excel, amounts are in negative. But they are written with a “.” where there should be a comma “,”. 55.48 instead of 55,48.

Do you know if it is possible to change it?

Kind Regards
Angel

1 Like

1 Like

Hello,

I am doing this but it is not working:

Message error: CultureInfo not defined.

Thanks

@Angel_Llull
refer to my post from above
import system.globalization

Many thanks! It worked

@Angel_Llull
Perfect, I am happy that it is working.
May I ask you to set back the solution flag back to @AndersJensen as he inital brought the essentials into the discussion. Thanks

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