Dim number As Variant 
If (INT(number) = number) Then

If (INT(number)/number = 1) Then

If (TypeName(number) = "Integer") Then

If a variable needs to contain a whole number you can use Integer or Long.
If a variable needs to contain a fraction you can use Single, Double or Currency.

Computers can also store numbers as fixed-point numbers.
You can see an example of this in the Currency VBA data type explained above.
In the case of fixed-point numbers, the decimal points doesn't "float".
It remains fixed in a certain location and, therefore, the number has always a fixed number of digits after or before the decimal point.

Working with floating-point numbers, generally, demands more computational resources.
Therefore, the suggestion made in Mastering VBA for Microsoft Office 2013 is to use fixed-point numbers "whenever practical".

Floating Point Numbers

These are numbers that can be expressed as mm E ee, where mm is the mantissa and ee is the exponent (power of 10).

Removing Decimal Places

Returning Remainder

Using VBA
12.6 Mod 5 = 3


Only available in Excel


Avoid using floating-point data types. The Currency datatype is in fact faster than using the Single datatype because it doesn't use the floating point processor.

Overflow Run-Time Error


Overflow Run-Time Error

Dim myDouble As Double 
Dim myInteger As Integer
myDouble = 3276700
myInteger = 32767
myDouble = myInteger * 100 'TypeName(100) = Integer


© 2018 Better Solutions Limited. All Rights Reserved. © 2018 Better Solutions Limited