Problem with cint and division

Thread: Problem with cint and division

1. Senior Member
Join Date
Dec 1969
Posts
283

Problem with cint and division

I am doing some division to find out how many pages a certain number of entries will fit on. Using this expression:<BR><BR>pages = cint((cint(rows(5, i)) + 1) / 15) <BR><BR>- in this case rows(5, i) returns 23, of this I am sure, I print it out. Now from the way cint is explained and exampled on all the pages I have seen this seems like it should be 1. <BR>(23+1)/15=24/15=1.5??? cint of that should be 1 but I get 2. Latter on I do something similar: <BR><BR>pages = cint(100/30) <BR><BR>(just killed putting any real values in out of frustration) and here I get the "right" value of 3. I mean I can do this some other way so it&#039;s not like this is a devastating thing BUT why in the world is this hapening?

2. Senior Member
Join Date
Dec 1969
Posts
283

cint rounds doesn't it?

I was just looking at all the examples of cint i saw and they would all round down my "problem" on the other hand would round up, think that&#039;t the problem.

3. Senior Member
Join Date
Dec 1969
Posts
16,931

RE: cint rounds doesn't it?

Yep, if you check the documentation for CInt (VBScript Reference link on the left, then CInt function), it tells you exactly under which conditions it&#039;ll round up and which conditions it&#039;ll round down.<BR><BR>Craig.

4. Senior Member
Join Date
Dec 1969
Posts
16,931

RE: cint rounds doesn't it?

Btw, if you want to "round down" to an integer, then investigate the Int() function.<BR><BR>Again, same place (VBScript Reference).<BR><BR>Craig.

5. Senior Member
Join Date
Dec 1969
Posts
283

RE: cint rounds doesn't it?

I had to round up so I used int with a modulus check to see if I should add an extra number

Posting Permissions

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