Logo

Hacker’s Guide to Visual FoxPro
An irreverent look at how Visual FoxPro really works. Tells you the inside scoop on every command, function, property, event and method of Visual FoxPro.

INT(), ROUND()

These two functions are for losing precision. INT() removes the decimal portion of a number. ROUND() lets you specify the desired precision and then it rounds more or less according to the usual rounding rules.

Usage

nNoDecimals = INT( nNumber )
nRounded = ROUND( nNumToRound, nPlaces )

Parameter

Value

Meaning

nNumber or nNumToRound

Numeric, Float, Integer, Double or Currency

Number to be processed.

nPlaces

0

Rounds to the nearest integer.

Positive

Rounds to the specified number of decimal places.

Negative

Rounds to the specified power of 10. For example, passing nPlaces=-2 rounds to the nearest hundred.

We were taught that when the first digit being dropped is 5, you look at the digit to its left—if it’s even, you round down; if it’s odd, you round up. ROUND() doesn’t do it that way—it always rounds up on a 5. Beware of this if you’re doing statistical or engineering calculations where such things matter.

For positive numbers, INT() and FLOOR() are the same. For negative numbers, INT() is the same as CEILING().

Example

? INT(37.2738)          && Returns 37
? ROUND(37.2738,0)      && Returns 37
? ROUND(37.2738,1)      && Returns 37.3
? ROUND(37.2738,2)      && Returns 37.27
? ROUND(37.2738,3)      && Returns 37.274
? ROUND(37.2738,-1)   && Returns 40
? ROUND(37.2738,-2)     && Returns 0
? ROUND(-11.92,0)       && Returns -12
? ROUND(-11.92,1)       && Returns -11.9
? ROUND(-11.92,-1)      && Returns -10

See Also

Ceiling(), Floor(), Max(), Min()