Summing values in variables

Hi, I would like my robot to sum up 5 variables and save the result in a new variable, how can I do that?

when variables are numbers (int, double…)

Assign Activity:
mySum = {va1,var2,var3,var4,var5}.Sum()

otherwise let us know the details e.g. when string, whic formatings do have the values

1 Like

@sullivanne
image
Or Instead of creating 5 variables use arrays for summing,Please follow this approach

1 Like

Hello, thank U, but I need to sum up, e.g. the following values: 500.00 + 400.00

we assume the dot is a decimal seperator and the datatype is string
so we can do
mySum = {va1,var2,var3,var4,var5}.Sum(Function (x) CDbl(x))

1 Like

@sullivanne


ArrVar=New Double() {100.00, 19.00,12.13,87}
1 Like

Thank You, yes, variables are of type string. I have error :frowning:
image

I changed it to type System.Double and it worked, but instead of 900.00 (500.00+400.00) it showed me a sum: 9000

we would prefer that you will share on the begin all relevant details like input, datatypes, expected output / expected output datatype

this is correct for a double, as there is no fraction

When a particular format is needed then we would do:

Assign Activity
mySum | DataType: string =
{va1,var2,var3,var4,var5}.Sum(Function (x) CDbl(x)).toString("F2")

1 Like

Sorry, I’m a beginner.
image
Instead of 900,00 (500,00+400,00=900,00) :frowning: All type are string.

As already mentioned above
grafik

When string of a number is using the comma as decimal seperator we can do:
grafik

and can also making it more compact, when using a cultureinfo variable representing the specific cultureinfo

1 Like

Hi @sullivanne

str1 = "500,00"

str2 = "400,00"

total = {str1, str2}.Select(Function(num) Convert.ToDecimal(num.Replace(",", "."))).Sum().ToString("N2").Replace(".", ",")

Check the below flow for better understanding:

Regards

1 Like

In Addition to above we should keep in mind
N2 and F2 is not the same (inserted separators for longer numbers)
grafik

So we also recommend to use CultureInfos instead of String Replaces as we can avoid side effects like
grafik
where
12,345,678.98 is the right default format
OR
12.345.678,98 is the right format of a eg. DE Culture

1 Like

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