Siebel eScript Language Reference > Siebel eScript Commands > Math Objects >
Math.round() Method
This method rounds a number to its nearest integer. Syntax
Math.round(number)
|
|
number |
A numeric literal or numeric variable |
Returns
The integer closest in value to number. Usage
The number parameter is rounded up if its fractional part is equal to or greater than 0.5 and is rounded down if less than 0.5. Both positive and negative numbers are rounded to the nearest integer. Example
This code fragment yields the values 124 and -124. var a = Math.round(123.6); var b = Math.round(-123.6) TheApplication().RaiseErrorText(a + "\n" + b)
NOTE: Rounding may not be precise if you multiply or divide a value and then round it. Multiplication and division lead to precision loss.
Example
This code fragment illustrates precision loss due to multiplication. var n = 34.855; n = n* 100; var r = Math.round(n)
The value of n is 3485.499999999999995 instead of 3485.5. When rounded this results in 3485 instead of 3486. Example
This code fragment provides a workaround for the loss of precision due to multiplication. var n = parseFloat(34.855); n = parseFloat(n1b*100.0); var r = Math.round(n);
See Also
Clib.modf() Method toFixed() Method ToInteger() Method ToUint16() Method ToUint32() Method
|