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 data type because it doesn't use the floating point processor.
Overflow Run-Time Error
link - https://stackoverflow.com/questions/17315650/overflow-when-multiplying-integers-and-assigning-to-long
Overflow Run-Time Error
Dim myDouble As Double
Dim myInteger As Integer
myDouble = 3276700
myInteger = 32767
myDouble = myInteger * 100 'TypeName(100) = Integer
link - https://stackoverflow.com/questions/17315650/overflow-when-multiplying-integers-and-assigning-to-long
© 2023 Better Solutions Limited. All Rights Reserved. © 2023 Better Solutions Limited TopNext