Skip to content

FIX

Syntax

FIX(X)

Versions: Extended, Disk

Description

Returns the truncated integer part of X. FIX(X) is equivalent to SGN(X)*INT(ABS(X)). The major difference between FIX and INT is that FIX does not return the next lower number for negative X.

Examples

Basic truncation:

PRINT FIX(58.75)
58
Ok
PRINT FIX(-58.75)
-58
Ok

Using FIX for array indexing with floating-point calculations:

10 DIM VALUES(10)
20 FOR I = 1 TO 10: VALUES(I) = I * 10: NEXT I
30 X = 3.7
40 INDEX = FIX(X)    ' Truncate to 3, not 4
50 PRINT "VALUE AT INDEX"; INDEX; "IS"; VALUES(INDEX)
VALUE AT INDEX 3 IS 30
Ok

Note: FIX is useful for converting floating-point results to array indices, ensuring truncation toward zero rather than rounding down (which INT does for negative numbers).

See Also

  • ABS - Return the absolute value of a number (removes negative sign)
  • ATN - Returns the arctangent of X in radians
  • COS - Returns the cosine of X in radians
  • EXP - Returns e to the power of X
  • INT - Return the largest integer less than or equal to a number (floor function)
  • LOG - Returns the natural logarithm of X
  • RND - Returns a random number between 0 and 1
  • SGN - Returns the sign of X (-1, 0, or 1)
  • SIN - Returns the sine of X in radians
  • SQR - Returns the square root of X
  • TAN - Returns the tangent of X in radians