xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

Round()

Rounds a numeric value to a specified number of digits

Syntax

Round( <nNumber>, <nDecimals> ) --> nRounded

Arguments

<nNumber>
This is the numeric value to round.
<nDecimals>
If the parameter is a positive number, it specifies the number of decimal places to retain after the decimal point. If specified as negative value, Round() operates on the digits before the decimal point, thus rounding integer numbers.

Return

The function returns the rounded numeric value.

Description

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.

Info

See also:Abs(), Int(), SET DECIMALS, SET FIXED, Str(), Val()
Category: Numeric functions
Source:rtl\round.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

// 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

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe