I am new to Uipath, i struck in converting string to Integer.
here is the scenario: i am scraping value from my application i .e $100 , like wise i have 3 variables $100 , $20 and $20
now i want to do some mathematical function (1st variable * 2nd variable/100 = 3rd variable)… while executing am getting string variables cannot be multiplied error is showing…
so can some one please help me out me out how i can do this.
@arivu96
I’d advise against using integers to store monetary values, you’ll lose precision.
@ClaytonM
Decimal should be used for monetary values. Double is close, but it loses precision with large/very small numbers (and with multiplications it’s not that hard to get there).
For both I’d say using string.replace to get rid of currency number is not the best approach. It’s also safer to use .Parse (or .TryParse) instead of convert, as it allows specifying culture and number styles.
For example:
(requires System.Globalization namespace to be imported) decimalFromDollars = Decimal.Parse("$100", NumberStyles.Currency, CultureInfo.CreateSpecificCulture("en-US")); decimalFromEuro = Decimal.Parse("€100", NumberStyles.Currency, CultureInfo.CreateSpecificCulture("de-DE")); decimalFromPLN = Decimal.Parse("100 zł", NumberStyles.Currency, CultureInfo.CreateSpecificCulture("pl-PL"))
Good tip on using .Parse. I couldn’t remember the Currency style off the top of my head. But, does that work even if there is no $ in order to be flexible?
individual field flags define style elements that may be, but do not have to be, present in the string representation of a decimal number for the parse operation to succeed
For currency its currency symbol, thousand and decimal separators, white space (iirc, on mobile now).
Edit - checked
And trailing / ending sign, and parentheses (indicates negative number).
“Replace” is a member of strings so you just need to convert your Generic value to a string or use a String variable type.
“.ToString” will convert any non-string value to a string to be used with “Replace” or other string members. variable1.ToString.Replace( )
OK. I’m reading a CSV file and one of the fields (TaxID) has a dash and I’m trying to remove the dash.
I’ve used this: Convert.ToInt32(CSVCompanyTaxID.Replace(“-”, “”))–But i get an error saying Cannot assign from type ‘System.Int32’ to type ‘System.String’ in Assign acitivity ‘Company Tax ID Remove Dash Variable Generation’.
I’ve used some other expressions but nothing is working right now any suggestions?
Thanks. So here is the whole picture of what I’m trying to do:
I have the CSVCompanyTaxID as an argument and i have it as a String.
So my first step is to assign the CSVCompanyTaxID to the column in the CSV file. That works. But now I was asked to remove the dash in the field and that is when i put that conversion in my logic.
But i get errors.
The first error is:
The second error is:
The third error is:
So what am I needing to do? I know it is simple but I’ve ran out of ideas at the moment.