| xHarbour Reference Documentation > Function Reference |
![]() |
![]() |
![]() |
Rounds a numeric value to a specified number of digits
Round( <nNumber>, <nDecimals> ) --> nRounded
The function returns the rounded numeric value.
Round() is a numeric function used to round numbers to a given number of decimal places. Digits 5 to 9 are rounded up, while digits 0 to 4 round down.
| See also: | Abs(), Int(), SET DECIMALS, SET FIXED, Str(), Val() |
| Category: | Numeric functions |
| Source: | rtl\round.c |
| LIB: | xhb.lib |
| DLL: | xhbdll.dll |
// The example demonstrates results of Round() and how SET FIXED
// influences the display of rounded numbers.
PROCEDURE Main
SET DECIMALS TO 4
SET FIXED ON
? Round( 1234.5678, 0) // result: 1235.0000
? Round( 1234.5678, 1) // result: 1234.6000
? Round( 1234.5678, 2) // result: 1234.5700
? Round( 1234.5678, 3) // result: 1234.5680
? Round( 1234.5678,-1) // result: 1230.0000
? Round( 1234.5678,-2) // result: 1200.0000
? Round( 1234.5678,-3) // result: 1000.0000
SET FIXED OFF
? Round( 1234.5678, 0) // result: 1235
? Round( 1234.5678, 1) // result: 1234.6
? Round( 1234.5678, 2) // result: 1234.57
? Round( 1234.5678, 3) // result: 1234.568
? Round( 1234.5678,-1) // result: 1230
? Round( 1234.5678,-2) // result: 1200
? Round( 1234.5678,-3) // result: 1000
RETURN
http://www.xHarbour.com