Q(uick)BASIC Function: FIX

Quick View

FIX

A math function that returns the truncated integer part of a numeric expression

Worth knowing

Useful and cross-version information about the programming environments of QBasic and QuickBasic.

Syntax
  • FIX(numeric-expression)
  • INT(numeric-expression)
Description/Parameter(s)
numeric-expression Any numeric expression.
Example
PRINT FIX(12.49), FIX(12.54) 'Output is: 12 12 PRINT INT(12.54), INT(-99.4) 'Output is: 12 -100

See also:

Syntax
  • FIX(numeric-expression)
Description/Parameter(s)

If x is a numeric expression, then FIX(x) is equivalent to SGN(x)*INT(ABS(x)). The difference between FIX and INT is that for negative x, FIX returns the first negative integer greater than x, while INT returns the first negative integer less than x.

Example

The following statements illustrate the differences between INT and FIX:

CLS ' Clear screen PRINT INT(-99.8) PRINT FIX(-99.8) PRINT INT(-99.2) PRINT FIX(-99.2)

Sample Output:

-100 -99 -100 -99
Syntax
  • FIX(x#)
Description/Parameter(s)

Usage Notes

  • FIX(x#) is equivalent to SGN(x#)*INT(ABS(x#)). The difference between FIX and INT is that for negative x#, FIX returns the first negative integer greater than x#, while INT returns the first negative integer less than x#.
Example

This example compares output from INT, CINT, and FIX, the three functions that convert numeric data to integers.

CLS 'Clear screen. PRINT " N", "INT(N)", "CINT(N)", "FIX(N)": PRINT FOR I% = 1 TO 6 READ N PRINT N, INT(N), CINT(N), FIX(N) NEXT DATA 99.3, 99.5, 99.7, -99.3, -99.5, -99.7

Sample Output:

99.3 99 99 99 99.5 99 100 99 99.7 99 100 99 -99.3 -100 -99 -99 -99.5 -100 -100 -99 -99.7 -100 -100 -99