Test for a whole number

# Thread: Test for a whole number

1. Senior Member
Join Date
Dec 1969
Posts
310

## Test for a whole number

Please excuse me for asking what is a very simple question. I have searched on the web and this msgboard for a solution but have not found one. <BR><BR>I have this bit of code:<BR><BR>TotalPages = TotalResults/PageSize &#039;How many pages of results?<BR><BR>and I want to test if the TotalPages variable is a whole number. <BR><BR>If it is a whole number (e.g. 10) then I want to do one thing, <BR><BR>if it is not a whole number, I want to do something else. <BR><BR>I have looked at the CInt() function, on the technical docs site, but this only seems to round up the variable, same with Fix() and Int(). <BR><BR>I need something to say e.g. <BR><BR>if IsWholeNumber(TotalPages) = TRUE then<BR> do this<BR> else<BR> do that<BR>end if<BR><BR>Thanks<BR><BR>Jim

2. Senior Member
Join Date
Dec 1969
Posts
449

## If you..

expect the number to have only 1 decimal place then you could just use &#039;mod&#039;<BR>ie<BR>TotalPages mod 10 &#062; 0 then &#039;you have a remainder<BR>Otherwise you can use &#039;fix&#039; or &#039;int&#039; to return the whole number and subtract that from the result<BR>ie<BR>isWholeNumber = TotalPages - Int(TotalPages )<BR>if isWholeNumber &#062; 0 then &#039;you have a remainder<BR>

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

## Yeah, or:

Function IsWholeNumber(sString)<BR> IsWholeNumber = False<BR> If IsNumeric(sString) = False Then Exit Function<BR> IsWholeNumber = (CInt(sString) = CDbl(sString))<BR>End Function<BR><BR>Something like that?<BR><BR>Craig.

4. Senior Member
Join Date
Dec 1969
Posts
1,843

## Re: Yeah, Or:

Function IsWholeNumber(sString)<BR> IsWholeNumber = False<BR> If IsNumeric(sString) = True Then<BR> IsWholeNumber = int(sString) = sString<BR> End If<BR>End Function<BR><BR>...Instead of converting the datatype twice, just use the Int() function to get the integer portion of the number and see if that&#039;s the same as the original number. Not sure if it is faster, but I think it would be...<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
•