Forum Discussion

gdave's avatar
gdave
Regular Contributor
3 years ago

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.

 

11 Replies

  • Marsha_R's avatar
    Marsha_R
    Champion Level 3

    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.

    • tphillips's avatar
      tphillips
      Frequent Contributor

      Looks like you might need to do some parsing too, to remove the commas and currency symbol

    • gdave's avatar
      gdave
      Regular Contributor

      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

       

       

       

      • AlexKaras's avatar
        AlexKaras
        Champion Level 3

        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.