Calculator
The Calculator step provides predefined functions that you can run on input field values. Use Calculator as a quick alternative to custom JavaScript for common calculations.
To use Calculator, specify the input fields and the calculation type, and then write results to new fields. You can also remove temporary fields from the output after all values are calculated.
Step name
Step name: Specify the unique name of the Calculator step on the canvas. You can customize the name or leave it as the default.
Options
Fill in the following fields in the table. The values in Field A, Field B, and Field C are used by the selected calculator function in the Calculation column.
New field
Specify the name of the field to create.
Calculation
When you click or press in this field, the Select the calculation type dialog box appears. Select the calculator function to use in the transformation. For details, see Calculator functions list. Use the Filter field to search for a specific function.
Field A, Field B, and Field C
Enter the field(s) that the calculator function uses.
Value type
Select the field’s data type from the list, or enter it manually.
Length
Specify the length of the field, based on the Value type (for example: Number = total number of significant figures; String = total string length; Date = length of printed output, such as yyyy for a year).
Precision
Specify the number of floating-point digits for Number fields.
Remove
Remove this field from the output after all values are calculated. This option is useful for removing temporary values. Select Y or N.
Conversion mask
Specify a format for the field, such as a date format. For common date formats you can use in this step, see Common Formats.
Decimal symbol
Specify the decimal symbol to use (dot . or comma ,). For example: 5,000.00 or 5.000,00.
Grouping symbol
Specify the thousands separator to use (dot . or comma ,). For example: 5,000 or 5.000.
Currency symbol
Specify the currency symbol to use, such as $ or €.
The Calculator step also provides the following option:
Throw an error on non existing files: Select this option to fail the transformation when a calculation references a file that does not exist (for example, checksum functions).
Calculator functions list
Troubleshooting
The following are frequently asked questions about the Calculator step.
Length and precision
Question
I made a transformation using the A / B function and it rounded incorrectly. I entered integers in Field A and Field B, but my result type was a number, so I would expect the integers to be converted to numbers before executing the division.
For example, when I execute 28/222, the result is 0.0 instead of 0.1261. It seems the result type is ignored. If I change the values in Field A and Field B to numbers (6, 4), my result is 0.12612612612612611, which still ignores the result type (4 places after the decimal point).
Suggested solution
Length and precision are metadata properties. PDI converts to the required metadata type when results are written to a target (such as a file or table), not during the transformation execution.
If you want to round to a specific precision, do the rounding in another step.
Also, rounding floating-point numbers can be misleading because floating-point values are stored as approximations. For example, 0.1261 might be stored as 0.126099999999 or 0.1261000000001.
For example, when numbers are stored in an output table, the calculation is rounded using BigDecimals. This behavior is also true for the Text File Output step. If you specify Integer as the result type, the internal number format is retained.
See Text File Output for details.
Data types
Question
How do the data types work internally?
Suggested solution
If you multiply an integer and a number, the result is always rounded. The Calculator step uses the data type of the value on the left side of the calculation (the value in Field A) as the driver for the calculation.
If you want more precision, put the number value in Field A. Alternatively, change Field A to the Number data type.
Rounding method for the Round (A, B) function
Starting in Pentaho 6.0, the Round (A, B) function rounds to the nearest positive infinity number (“Round half to ceiling”). Before version 6.0, Round (A, B) used the “Round half to even” method (also called unbiased rounding, bankers’ rounding, or Gaussian rounding).
Use the following steps to override the default “Round half to ceiling” method and use the “Round half to even” method.
Last updated
Was this helpful?

