Automation suggestion using string values

Hi All,

Please suggest an idea to achieve below operation

A= “592,20”
B=“99,20”

and my result should be C=“691,40”

@Ajith3,

You can achieve this in UiPath by parsing the strings into numerical values, performing the addition, and then formatting the result back into the desired string format.

Here’s how you can do it:

  1. Use the Assign activity to replace the commas with dots, as the comma is treated as a decimal separator in some locales:

A = A.Replace(“,”, “.”)

B = B.Replace(“,”, “.”)

  1. Convert the strings into Double using the CDbl() function:

A_Double = CDbl(A)

B_Double = CDbl(B)

  1. Add the two values:

C_Double = A_Double + B_Double

  1. Convert the result back to a string with the comma as a decimal separator:

C = C_Double.ToString.Replace(“.”, “,”)

Now C will be “691,40” as expected.

LLM helped me to write this but it’s validated by me.

Hi @ashokkarale ,

I am getting C=691,4000000000001

@Ajith3 , are you asking how to add 2 numbers?

@sudster , yes but my inputs and output should be in string

Hi @Ajith3

Please try with this

A_Decimal = Convert.ToDecimal(A.Replace(",","."))
B_Decimal =Convert.ToDecimal(B.Replace(",","."))
C= (A_Decimal+B_Decimal).ToString.Replace(".",",")

@Ajith3,

Use this solution.

Sample Code:
Main.xaml (16.6 KB)

Output:

All you need is to set the CurrentCulture to one of the European countries.

image

image

Edit: To fix some failure modes. Sorry, I had to edit multiple times because as I was testing, I found more issues.

Note: This solution will give you 2 decimal places in the output in all cases. If this is not a requirement, one of the other solutions will be easier.

@ashokkarale could you please help me with this error ?
I have downloaded the xaml, which you sent.

@Ajith3,

Here is full project. I guess there could be package dependency which is resulting in this error.

Extract and use this project.

TestProject.zip (46.2 KB)

@ashokkarale ,

Format value activity accepting only ‘Generic Value’.
Thanks for your suggestion. Its working now.

1 Like

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