What is the difference...

Results 1 to 3 of 3

Thread: What is the difference...

  1. #1
    Join Date
    Dec 1969

    Default What is the difference...

    Ok, I am a real idiot when it comes to VBscript. I have no formal training. My only teachers are you guys.... so here is today&#039s silly question:<BR>What is the difference beteween int(x) and Cint(x)?<BR><BR>I really need to know!<BR><BR>Thanks,<BR><BR>Edward

  2. #2
    Steve Cimino Guest

    Default RE: What is the difference...

    Check yesterday&#039s messages in the ASP Forum... Bill Wilkenson has explained this already in an excellent post.

  3. #3
    Join Date
    Dec 1969

    Default Thanks a million!

    In case anyone else needs it, here is that post.....<BR><BR>Great question! Put in FAQ?<BR>Bill Wilkinson - 31 Aug - 03:01:22 PM<BR>---------------------------------------------------------------<BR>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.

Posting Permissions

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