[thelist] ASP: cInt() VS int()

Paul Cowan evolt at funkwit.com
Tue Aug 20 20:23:00 CDT 2002


Ken Kogler wrote:
> I was using cInt() in an app I'm writing, but as soon as the number goes
> over the magical limit (36,000 and change), I get an overflow error. So
> I switched to int(), which can handle bigger numbers.
>
> But I just discovered that int() is dropping everything after the
> decimal. MSDN's docs say that it's designed to do that (another
> "feature" I guess), but I'm doing multiplication with currency, and I
> need the part after the decimal!

int() and cint() are different things.

cint() says "take this thing, which might be a string, date, or lord-knows-
what-else, and convert it to an integer"

int() says "remove the decimal point from this, bringing it to the nearest
whole number" (it's the same as fix(), but works differently for negative
numbers)

If you want the equivalent of cint(), but for bigger numbers, it's not
int(), but clng() -- "convert to long"; a long is like an int, but is
32 bits instead of 16 (i.e. can hold larger values).

If you're needing the decimals, then you shouldn't be using any of
the integer functions, but should be using something like cdbl() --
"convert to double" -- which is a floating-point data type. Or, given
you're talking currencies, use ccur() -- "convert to currency".

This is one of the rather nasty parts of using a weakly-typed language
like VBSCript.

Hope this helps,

Paul




More information about the thelist mailing list