ROUND( ) Function

Returns a numeric expression rounded to a specified number of decimal places.

ROUND(nExpression, nDecimalPlaces)

Parameters

  • nExpression
    Specifies the numeric expression whose value is to be rounded.

  • nDecimalPlaces
    Specifies the number of decimal places nExpression is rounded to.

    If nDecimalPlaces is negative, ROUND( ) returns a whole number containing zeros equal in number to nDecimalPlaces to the left of the decimal point. For example, if nDecimalPlaces is –2, the first and second digits to the left of the decimal point in the value are 0.

Return Value

Numeric data type. ROUND( ) returns a value rounded to the nearest decimal position as specified by nDecimalPlaces.

Remarks

ROUND( ) disregards the number of decimal places specified by the SET DECIMALS command. To display a larger number of decimal places than specified by nDecimalPlaces in ROUND( ), use SET FIXED ON with SET DECIMALS.

Example

The following example specifies that resulting values display with four decimal places using the SET DECIMALS and SET FIXED commands. The example clears the main Visual FoxPro window using the CLEAR command, performs rounding operations with the ROUND( ) function, and displays the results using the ? command. The example restores the default startup values using SET FIXED and SET DECIMALS.

SET DECIMALS TO 4
SET FIXED ON     
CLEAR
? ROUND(1234.1962, 3) && Displays 1234.1960
? ROUND(1234.1962, 2) && Displays 1234.2000
? ROUND(1234.1962, 0) && Displays 1234.0000
? ROUND(1234.1962, -1)  && Displays 1230.0000
? ROUND(1234.1962, -2)  && Displays 1200.0000
? ROUND(1234.1962, -3)  && Displays 1000.0000
SET FIXED OFF  
SET DECIMALS TO 2

See Also

Reference

STR( ) Function

CEILING( ) Function

FLOOR( ) Function

INT( ) Function

SET DECIMALS Command

SET FIXED Command

Other Resources

Functions