Click or drag to resize

Round Function

Round a number to a specified number of digits.

Namespace:  XSharp.RT
Assembly:  XSharp.RT (in XSharp.RT.dll) Version: 2.10
Syntax
 FUNCTION Round(
	nNumber AS USUAL,
	siDecimals AS LONG
) AS USUAL
View Source

Parameters

nNumber
Type: Usual
The number to round.
siDecimals
Type: Int32
The number of decimal places to retain.  Specifying a 0 or negative value for <siDecimals>  rounds to whole numbers.  A negative <siDecimals> also indicates the number of digits to the left of the decimal point to round (see the example).

Return Value

Type: Usual
Remarks
Digits below 5 are rounded down.  Digits from 5 to 9 are rounded up. The display of the return value does not obey the decimals setting unless SetFixed() is TRUE.  If SetFixed() is FALSE, the display of the return value contains  <siDecimals> decimal digits if  <siDecimals> is greater than 0, and zero decimal digits if  <siDecimals> is less than or equal to 0.
Examples
These examples round values with decimal digits:
X#
SetDecimal(2)
SetFixed(TRUE)
? Round(10.4, 0)                                        // 10
? Round(10.5, 0)                                        // 11
? Round(10.51, 0)                                        // 11
? Round(10.49999999999999, 2)                        // 10.50
These examples use a negative <siDecimals> argument to round numeric values to whole numbers:
X#
? Round(101.99, -1)                                        // 100
? Round(109.99, -1)                                        // 110
? Round(109.99, -2)                                        // 100
See Also