Using clng or cInt

Thread: Using clng or cInt

1. Member
Join Date
Dec 1969
Posts
37

Using clng or cInt

I&#039;m having trouble with my decimals getting dropped. The column that I bring back from my SQL DB has two decimal places. If I just do a Response.Write objRS("hoursworked"), it displays correctly. But as soon as I assign it to a varable, the decimal places get dropped. Any ideas? <BR><BR>If OldProj = NewProj then<BR>sum = cLng(Sum) + cLng(objRS("hoursworked"))<BR>end if<BR><BR>

2. Senior Member
Join Date
Dec 1969
Posts
10,852

RE: Using clng or cInt

That&#039;s cause you&#039;re telling it to. Integer values don&#039;t *have* any decimal places. Try CBbl() instead.

3. Senior Member
Join Date
Dec 1969
Posts
10,852

And of course that should have been...

CDbl(yourValue)

4. Senior Member
Join Date
Dec 1969
Posts
96,118

Doing what you tell it to!

CINT says "if possible, convert my argument to an integer between -32768 and +32767" (else generate an error)<BR><BR>CINT says "if possible, convert my argument to an integer between -2147483648 and +2147483647" (else generate an error)<BR><BR>And if you weren&#039;t aware that the definition of an "integer" is "a whole number; a number with no fractional part; a number with no digits after the decimal point" then back to 5th grade arithmetic.<BR><BR>So are you going to explain what motivated you to use CLNG to convert perfectly good NON-integer numbers into integers?<BR><BR>Incidentally, if the data type of the field in the DB is DECIMAL, then you *might* need to use CDBL() to convert it to a numeric type that VBScript can work with. Is that what you thought you were doing with CLNG?<BR><BR><BR>

5. Senior Member
Join Date
Dec 1969
Posts
2,958

Uhh

CINT says "if possible, convert my argument to an integer between -32768 and +32767" (else generate an error) <BR><BR>CINT says "if possible, convert my argument to an integer between -2147483648 and +2147483647" (else generate an error) <BR><BR><BR>Huh?

6. Senior Member
Join Date
Dec 1969
Posts
96,118

LOL! Good pasting...

...not enough editing.<BR><BR>CLNG is of course the function with the +/- 2 billion range.<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
•