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:
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/)