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
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
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
One way...

A1 = some number

=A1-INT(A1)=0
 
Upvote 0
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

Real numbers is a much larger set. Therefore:

=A1-TRUNC(A1)=0
 
Upvote 0
Real numbers is a much larger set. Therefore:

=A1-TRUNC(A1)=0

Aladin, is there a case where this would return a different result than the formula Biff suggested?

When A1 is a negative number, the value of A1-TRUNC(A1) will be different than A1-INT(A1); however it would appear to still return True only for whole numbers.
 
Upvote 0
Nothing wrong with any of the responses you've received, but I find the two below more 'direct.' ;-)
=MOD(A1,1)=0. This works because Excel supports real numbers in the MOD function.
=A1=INT(A1) This also works in VBA, as has already been pointed out.
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
 
Upvote 0
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

Forum statistics

Threads
1,224,514
Messages
6,179,220
Members
452,895
Latest member
BILLING GUY

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