Diff between INT and CINT

Results 1 to 2 of 2

Thread: Diff between INT and CINT

  1. #1
    BooYeah Guest

    Default Diff between INT and CINT

    When I have a string that I want to get the numeric value of, why does CINT sometimes return an error, even if the string passes the ISNUMERIC test, yet INT works just fine? Is there some guideline for which one to use?

  2. #2
    Join Date
    Dec 1969

    Default Great question! Put in FAQ?

    First of all, one BIG difference is that INT is a *MATH* function that returns only the integer part of a number.<BR><BR>So Int(37.65) returns 37. There is also a Round function, such that Round(37.65) returns 38.<BR><BR>You aren&#039t really supposed to use INT to convert from string to number, and in Visual Basic (not VBScript), you can&#039t. But because all data types in VBS are "variants", what actually happens is the calling INT to convert a string *first* calls CDbl (Convert to DouBLe) and then does the integer conversion on the double number.<BR><BR>CInt, on the other hand, is a *CONVERSION* function. Designed to convert from strings or what have you to integers. But watch out! CInt only handles SHORT integers. Numbers in the range -32768 to +32767. If your number is outside that range, you need to use CLng ("Convert to LoNG integer"). Its range is -2147483648 to +2147483647.<BR><BR>Note that INT will handle *either* short or long integers, which could easily explain why it will not exhibit an error when CInt will. Okay?<BR><BR>Finally, the other big difference is that, despite the name, CInt (and CLng) always *round* the numbers, if there are any fractional parts. <BR><BR>As a practical matter, if you do *not* want rounding, the easiest function to use is INT. If you *do* want rounding, use CLng. <BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts