Forum Discussion

gdave's avatar
gdave
Regular Contributor
6 years ago

Code Expression

Hi all

I've used the below code expression in my test:

"aqConvert.StrToInt(ProjectSuite.Variables.XX) * aqConvert.StrToInt(ProjectSuite.Variables.YY)"

 

The above code is suppose to multiply the values in 'variable.xx' & 'variable.yy' however I am unable to get the expected value which equals actual value. Screenshot examples below:

 

Variable XX & YY ValuesTest Run Result

In the above scenario, when you calculate 3.257*354.66, the expected value must be 1155.13 however I am not sure why test complete is calculating it to 1065. Any help on this will be much appreciated.

 

Thanks

GD

  • Hi,

     

    > now I am stuck with the rounding issue.

    Well, I still assume that you are dealing with money (i.e. currency data type)...

    There is no direct support for currency in DelphiScript. Below are quick ideas that came first to my head:

    -- Use already mentioned Round() function that seems to implement bank rounding rules and use it to create your own code to handle currency. As Round() rounds to integers, you will need to shift calculation base to the right as required, do calculations and than return back. E.g.:

    for the initial 3.257 * 354.66 = 1155.13 you need something like this (100 multiplier/divider is used because we are rounding to two digits after comma):

    (3.257 * 354.66) * 100 = 115512.762 ==> Round(115512.762) = 115513 ==> 115513 / 100 = 1155.13

     

    -- Ask your developers (or do it yourself) to create a DLL that conforms to TestComplete's requirements (see help for the DLL object) and implements currency calculations. Then call functions provided by this DLL;

    -- If .Net is installed on the computers where TestComplete tests are executed, then investigate if .Net provides currency calculation routines that can be called from TestComplete via the dotNET object and use them (https://stackoverflow.com/questions/2215601/money-data-type-for-net ?);

    -- Create a Script Extension in TestComplete using some already existing VBScript or JScript code/library and use this Script Extension from your code. (https://frontstuff.io/how-to-handle-monetary-values-in-javascript, http://openexchangerates.github.io/accounting.js/)

     

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    You are converting values to integers before multiplication. So the actual expression becomes:

    3 * 355 which equals to 1065.

     

    Note, that you are working with floating values. The exact result of multiplication done manually on paper is:

    3.257 * 354.66 = 1155.12762

    and you need to consider correct rounding in your verification code if you need to get rounded value of 1155.13

     

    I am guessing that you are working with the values of money type. I don't know what scripting language your test project is based on, but neither TestComplete itself, nor VBScript explicitly supports money calculations and you need to search for some sample code that implements correct roundings.

    I am not sure about JScript/JavaScript/Python - it is possible that they have internal support for money data type.

     

    • gdave's avatar
      gdave
      Regular Contributor

      Hi

      The test project is based on Delphi and you were right, now I am stuck with the rounding issue.

      I am not sure what verification code will help me with rounding the expected value to "1259.13". Any suggestions ?

       

      Thanks

      • AlexKaras's avatar
        AlexKaras
        Champion Level 3

        Hi,

         

        > now I am stuck with the rounding issue.

        Well, I still assume that you are dealing with money (i.e. currency data type)...

        There is no direct support for currency in DelphiScript. Below are quick ideas that came first to my head:

        -- Use already mentioned Round() function that seems to implement bank rounding rules and use it to create your own code to handle currency. As Round() rounds to integers, you will need to shift calculation base to the right as required, do calculations and than return back. E.g.:

        for the initial 3.257 * 354.66 = 1155.13 you need something like this (100 multiplier/divider is used because we are rounding to two digits after comma):

        (3.257 * 354.66) * 100 = 115512.762 ==> Round(115512.762) = 115513 ==> 115513 / 100 = 1155.13

         

        -- Ask your developers (or do it yourself) to create a DLL that conforms to TestComplete's requirements (see help for the DLL object) and implements currency calculations. Then call functions provided by this DLL;

        -- If .Net is installed on the computers where TestComplete tests are executed, then investigate if .Net provides currency calculation routines that can be called from TestComplete via the dotNET object and use them (https://stackoverflow.com/questions/2215601/money-data-type-for-net ?);

        -- Create a Script Extension in TestComplete using some already existing VBScript or JScript code/library and use this Script Extension from your code. (https://frontstuff.io/how-to-handle-monetary-values-in-javascript, http://openexchangerates.github.io/accounting.js/)