round()
The mathLib.round() system function rounds the value of an expression to a specified power of ten (for example, to the nearest thousands) and returns the result.
EGL carries out the rounding by adding 5 to the place to the right of the rounding point, then setting that place and all lower places to zero.
Syntax
mathLib.round(
numericVariable DECIMAL | SMALLFLOAT | FLOAT in,
powerOf10 INT in)
returns (result DECIMAL | SMALLFLOAT | FLOAT)
- numericVariable
- Input can be a variable or expression compatible with any of the above types.
- powerOf10
- The number of places [either to the left (positive) or to the right (negative) of the decimal point] by which numericVariable is to be rounded. This variable or expression must be compatible with the INT type.
- result
- The result of the rounding is returned as the same type as that to which numericVariable was assigned.
Examples
In the first example, the variable balance is
rounded to the nearest thousand:
balance FLOAT = 12345.6789;
rounder INT = 3;
balance = mathLib.round(balance, rounder);
// balance is now 12000.0000
If you change rounder to a value of -2, the function
rounds balance to two decimal places:
balance = 12345.6789;
rounder = -2;
balance = mathLib.round(balance, rounder);
// balance is now 12345.68