Sum of two variable values
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sum of two variable values
Hi all
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.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Looks like you might need to do some parsing too, to remove the commas and currency symbol
--------------------
Senior SQA Automation Engineer
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi
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
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
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.
https://community.smartbear.com/t5/Community-Champions/About-the-Community-Champions-Program/gpm-p/252662
================================
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks everyone, great conversation!
Hi @gdave! Please let us know if Alex's advice helped you further.
Sonya Mihaljova
Community and Education Specialist
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
hi @gdave -
You can trim the string using the substring or trim method of aqString.
https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqstring/substring.html
https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqstring/trim.html
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.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @ebarbera
Can this be achieved using code snippet ?
If yes, can you please help with possible approach ?
Thanks
G
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Emma
