Siebel VB Language Reference > VB Language Reference >

Int Function

This standard VB function returns the integer part of a number.





Any numeric expression


The integer part of number.


For positive numbers, Int removes the fractional part of the expression and returns the integer part only. For negative numbers, Int returns the largest integer less than or equal to the expression. For example, Int (6.2) returns 6; Int(-6.2) returns -7.

The return type matches the type of the numeric expression. This includes variant expressions that return a result of the same vartype as input, except vartype 8 (string) returns as vartype 5 (double) and vartype 0 (empty) returns as vartype 3 (long).

The effect of this function is the same as that of the Fix function, except in the handling of negative numbers. Thus:

  • Fix(-8.347) = -8
  • Int(-8.347) = -9

This example uses Int to generate random numbers in the range between the ASCII values for lowercase a and z (97 and 122). The values are converted to letters and displayed as a string.

Sub Button_Click
   Dim x As Integer, y As Integer
   Dim str1 As String, letter As String
   Dim randomvalue As Double
   Dim upper As Integer, lower As Integer
   Dim msgtext, newline
   upper = Asc("z")
   lower = Asc("a")
   newline = Chr(10)
   For x = 1 to 26
      randomvalue = Int(((upper - (lower + 1)) * Rnd) + lower)
      letter = Chr(randomvalue)
      str1 = str1 & letter
   'Need to waste time here for fast processors
      For y = 1 to 1500
      Next y
   Next x
   msgtext = "The string is:" & newline
      msgtext = msgtext & str1
End Sub

Related Topics

Exp Function
Fix Function
Log Function
Rnd Function
Sgn Function
Sqr Function

Siebel VB Language Reference Copyright © 2006, Oracle. All rights reserved.