MathLib.round function

MathLib.round rounds a value and returns the result.

Package

eglx.lang

Syntax
static function round(val1 float in, powOf10 int in) returns (float);

static function round(val1 smallfloat in, powOf10 int in) returns (smallfloat);

static function round(val1 decimal in, powOf10 int in) returns (decimal);
val1
Takes the numeric value being rounded.
powOf10
Takes the number of places by which the value is rounded. Specify a positive number to round the left of the decimal point. Specify a negative number to round to the right.
Example use

The next code sets balance to 12000.0000:

balance FLOAT = 12345.6789;
rounder INT = 3;
balance = mathLib.round(balance, rounder);
The next code sets balance to 13000.0000:
balance FLOAT = 12845.6789;
rounder INT = 3;
balance = mathLib.round(balance, rounder);
The next code sets balance to 12345.68:
balance FLOAT = 12345.6789;
rounder INT = -2;
balance = mathLib.round(balance, rounder);
Comments
Here is the rounding algorithm:
  1. Add 5 to the digit at the right of the rounding point.
  2. Increment the value of the digit at the rounding point, if step 1 made that change appropriate.
  3. Set to zero both the digit to which the 5 was added and all subsequent digits.

In the case of Java™, EGL uses methods in the Java StrictMath class that are equivalent to the EGL functions. This usage ensures that the runtime behavior is the same for every Java Virtual Machine.

Compatibility

Table 1. Compatibility
Target Issue
Java No issues.
JavaScript No issues.