Returns the integer portion of any number by truncating towards negative infinity.
...Int ( number )
Prerequisites
None
Parameters
number
A required numeric expression. The numeric expression can yield any type of result, i.e. Boolean, Byte, Double, Integer, Short or Single.
Remarks
The Int and Fix functions return the integer portion of any number by truncating the fraction part of the value. For positive numbers, these two functions are identical. However, for negative numbers, the Int function returns the first negative number less than or equal to the input expression value. Alternately, the Fix function returns the first negative number that is greater than or equal to the input expression value. For example:
Dim s_val As Single
s_val = Int(-1.2) ' Sets s_val equal to -2
s_val = Fix(-1.2) ' Sets s_val equal to -1
s_val = Int(-1.9) ' Sets s_val equal to -2
s_val = Fix(-1.9) ' Sets s_val equal to -1Unlike the conversion routines (e.g. CInt, CShort), these functions truncate their values rather than round them. For example:
Dim s_val As Single
s_val = Int(1.2) ' Sets s_val equal to 1
s_val = CInt(1.2) ' Sets s_val equal to 1
s_val = Int(1.9) ' Sets s_val equal to 1
s_val = CInt(1.9) ' Sets s_val equal to 2In addition, the conversion routines test the converted values to ensure that the returned value is within the range of a specific data type. The Int and Fix routines simply eliminate the fraction portion of any number and perform no range testing.
Examples
Dim s_val As Single
s_val = Int(3.14159) ' Sets s_val equal to 3
s_val = Int(3.99999) ' Sets s_val equal to 3
See Also