[Working with scripts]: User-Defined Function

Adding user-defined function into report will allow user to select their defined function from the UI which will skip the harass to add the script manually on every Field.

Before starting to create a user-defined function script you need to have some basic knowledge in scripting. Please refer to below for the available function before starting to create a new function.

Instruction:

  1. Place the user-defined function script(example PrecisionSum.js) into .\Repertoire\ext

  2. Open the template in Repertoire Designer or Remote Designer

  3. Double click on the ‘Data Field’ to open the ‘Properties’ option.

  4. Select ‘Field Type: Operation’ and select the user-defined function in the combo box located on the bottom.
    .
    UserDefinedFunction1

User-Defined Function Script:

Precision Summation(PrecisionSum.js):

This user-defined function will provide user with exact values after summation Double Type values.

In Java, double and float are internally represented as binary fractions according to the IEEE standard 754 and therefore the result will not be exact.

http://java.sun.com/docs/books/tutorial/java/nutsandbolts/datatypes.html

Example: Double Type of 1.52 and 0.51 will be 1.5200000000000001 and 0.5100000000000001 respectively.

Therefore summation 1.52 and 0.51 will give 2.0300000000000002 instead of 2.03.

The workaround will be to

  1. convert these values to BigDecimal

  2. Multiply all the values by 100 and sum them as Integer then divide the final result by 100. (Example (1.52100+0.51100)/100)

The above PrecisionSum.js is based on Workaround 2)