Int, Fix Functions

See AlsoX4DVWM              Example16XXZHD>Low

Return the integer portion of a number.





The argument number can be any valid numeric expression71RISN.  Both Int and Fix remove the fractional part of number and return the resulting integer value.

The data type3GYXY7 of the return value is the same as that of the number argument.  However, if number is a Variant8PHEAW3 of VarType7A68ZTZ 8 (String) that can be converted to a number, the return type will be a Variant of VarType 5 (Double).  If the numeric expression results in a Null1DDW7C0, Int and Fix return a Null.

The difference between Int and Fix is that if number is negative, Int returns the first negative integer less than or equal to number, whereas Fix returns the first negative integer greater than or equal to number.  For example, Int converts -8.4 to -9, and Fix converts -8.4 to -8.

Fix(number) is equivalent to:

   Sgn(number) * Int(Abs(number))


See Also

Data Type Conversion Functions1JQNQGO

Math FunctionsEK0VY1

Int Function, Fix Function Example

The example illustrates the difference between Int and Fix.  To try this example, paste the code into the Declarations section of a form.  Then press F5 and click the form.


Sub Form_Click ()

   Dim Msg, NL, TB                       ' Declare variables.

   NL = Chr(13) & Chr(10): TB = Chr(9)   ' Define newline, tab.

   Msg = "Int(-99.8) returns" & TB & Int(-99.8)

   Msg = Msg & TB & "Fix(-99.8) returns" & TB & Fix(-99.8)

   Msg = Msg & NL & "Int(-99.2) returns" & TB & Int(-99.2)

   Msg = Msg & TB & "Fix(-99.2) returns" & TB & Fix(-99.2)

   MsgBox Msg                            ' Display message.

End Sub