Sum of two variable values
I am trying to sum up the total of two different variables and store the value in a third variable. However, for some odd reasons, the variable (result) is reflecting the individual value of each variable and not the sum total. I am not sure what wrong have I done. Can some please advise ?
I would have expected a sum total of above two values to reflect in the result variable.
Thanks in advance.
Your result variable is of type String, so the result you are getting is a string. You'll need to change that to type Integer to get the sum of the original variable contents.
Looks like you might need to do some parsing too, to remove the commas and currency symbol
Senior SQA Automation Engineer
Thanks, it worked.
However I am experiencing a different issue now.
Issue 1: The property checkpoint doesn't match up but testcomplete still says that the property check point passed.
Issue 2: Is there a way I can ensure the expected value = actual value ? I've used the two variable type as integer however it seems that the sum total is rounded off automatically which has resulted in a rounded expected value. Thanks
You did not provide values that variables contain, but according to the checkpoint's screenshot, it is my guess that variables contain not numeric values, but some string values (currency symbol with the number).
If my guess is correct, then you should do the following:
-- Parse the value to be stored to the variable and strip everything except numeric value;
-- Set the project variable to be of double type;
-- Assign the value to the variable;
-- Repeat the above with the second value and variable;
-- Now values of project variables can be summed.
Note, that as you are totaling float values, the result might be not exact expected value but expected value plus/minus some delta caused by rounding. This is a usual problem for the mathematical operations over float numbers.
/Alex [Community Champion]
[Community Champions] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Champions]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Champion] signature is assigned on quarterly basis and is used with permission by SmartBear Software.
Thanks everyone, great conversation!
Hi @gdave! Please let us know if Alex's advice helped you further.
Community and Education Specialist
Thanks for the help.
Everything else worked fine. The only thing I am struggling with is parsing the value.
Would you be able to advise how do I go about 'Parse the value to be stored to the variable and strip everything except numeric value;'. Thanks
hi @gdave -
You can trim the string using the substring or trim method of aqString.
To do this I would write a short function to store the value into a variable then trim that variable, then you can do the checkpoint based on the trimmed variable.
Let me know if you have any questions on how to approach this.
hi @gdave -
I think we may need a short function here based on the fact that we will have to remove the comma and the dollar symbol.
What language is your project in - I would be happy to assist in writing the function.