Click or drag to resize

Round Function

X#
Round a number to a specified number of digits.

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

Parameters

nNumber
Type: Usual
The number to round.
siDecimals
Type: Long
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#
1SetDecimal(2)
2SetFixed(TRUE)
3? Round(10.4, 0)                    // 10
4? Round(10.5, 0)                    // 11
5? Round(10.51, 0)                    // 11
6? Round(10.49999999999999, 2)            // 10.50
These examples use a negative siDecimals argument to round numeric values to whole numbers:
X#
1? Round(101.99, -1)                    // 100
2? Round(109.99, -1)                    // 110
3? Round(109.99, -2)                    // 100
See Also