Fix, Int, Floor & Ceil and Trunc & Frac Functions

Purpose

Return the integer or fractional portion of a numeric expression.

Syntax

n = Ceil(x)
n = Floor(x)

n = Fix(x)
n = Int(x)

n = Trunc(x)
f = Frac(x)

f: floating point variable
x: any numeric variable
n: integer

Description

Ceil rounds up x to the next largest integer, while Floor rounds it down to the next smallest integer.

Trunc removes the fractional element of x and returns the integer, while Frac does the opposite and returns the fraction.

Finally, Int acts like Floor and rounds x down, while Fix is synonymous with Trunc and simply returns its integer element.

Example

Debug.Show

Debug "-- With Positive Numbers --"

Trace Ceil(3.4)         // Output: 4

Trace Floor(3.4)        // Output: 3

Trace Trunc(3.4)        // Output: 3

Trace Frac(3.4)         // Output: 0.4

Trace Int(3.4)          // Output: 3

Trace Fix(3.4)          // Output: 3

Debug

Debug "-- With Negative Numbers --"

Trace Ceil(-3.4)        // Output: -3

Trace Floor(-3.4)       // Output: -4

Trace Trunc(-3.4)       // Output: -3

Trace Frac(-3.4)        // Output: -0.4

Trace Int(-3.4)         // Output: -4

Trace Fix(-3.4)         // Output: -3

Remarks

CInt, or any of the integer Cxxx functions, acts differently to Int as it rounds the passed number to the nearest integer, as does Round.

See Also

CInt, FRound(), QRound(), Round()

{Created by Sjouke Hamstra; Last updated: 24/05/2020 by James Gaite}