Whole number question

JohnSearcy

Board Regular
Joined
Feb 6, 2006
Messages
101
I have forgotten somewhat, but what is the code to determine if a number is a whole number or not.
In other words:

5 = Whole number
7.86 = Not a whole number

I looked in the help files, but I couldn't find it. What would that be under?

Thanks,
John
 
While INT (or Int in VBA) is the more intuitive approach to getting the integer part, Excel and VBA's implementation is to round *towards* zero any non-integer number. So, if one were looking to extract only the integer part, TRUNC (or Fix in VBA) is the way to go.

However, in this case all we want to do is check if there is a fraction part. Consequently, any function would work just as well as any other.
INT(x) = x
TRUNC(x) = x
MOD(x) = 0
and in VBA
Fix(x) = x
Int(x) = x

and if one wanted, use FLOOR or CEILING (or the VBA counterparts).

Thanks Tushar,

I was asking about INT vs TRUNC, because if TRUC is better, then in VBA one should probably use Fix instead of Int

Code:
If Fix(x) = x Then

Sounds like they will both work fine and I appreciate your advice of MOD as an additional formula option.
 
Upvote 0

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce

Forum statistics

Threads
1,224,517
Messages
6,179,239
Members
452,898
Latest member
Capolavoro009

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top