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
@sullivanne
Or Instead of creating 5 variables use arrays for summing,Please follow this approach
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))
Thank You, yes, variables are of type string. I have error
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")
Sorry, I’m a beginner.
Instead of 900,00 (500,00+400,00=900,00) All type are string.
As already mentioned above
When string of a number is using the comma as decimal seperator we can do:
and can also making it more compact, when using a cultureinfo variable representing the specific cultureinfo
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
In Addition to above we should keep in mind
N2 and F2 is not the same (inserted separators for longer numbers)
So we also recommend to use CultureInfos instead of String Replaces as we can avoid side effects like
where
12,345,678.98 is the right default format
OR
12.345.678,98 is the right format of a eg. DE Culture
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.