Numbers


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

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

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


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


Application.Pi

Only available in Excel
Excel

Application.Pi 


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.




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

Top

Next