Numeric Data Types
- Last UpdatedJul 18, 2023
- 2 minute read
Numbers are expressed in VBA in decimal format by default, and can be stored in variables of different numeric data types-integer, long, single, double, and variant-providing different levels of numeric accuracy.
-
Integer (Integer data type) variables can only store whole number values (no decimal or fraction values) within the range -32,000 to +32,000. If you use a number outside this range, the long integer (Long data type) can store whole number values in the range -2.1 million to +2.1 million.
-
Floating point numbers contain both integer and fractional values with a floating decimal point. VBA provides both single precision (Single data type) and Double Precision (Double data type) variables for handling floating-point numbers.
-
Single-precision variables can store floating-point numbers within the range of approximately 3.4E-38 to 3.4E+38, with 7 significant digits and occupying 4 bytes of memory.
-
Double-precision variables can store floating-point numbers within the range of approximately 1.79D-308 to 1.79D+308, with 15 significant digits and occupying 8 bytes of memory.
For an explanation of exponential notation, see Exponential Notation.
The principal differences between single and double data types, are the significance they can represent, the storage they require, and their range. Double data type variables have a smaller range, but hold more precision and occupy more memory than single data type variables.
If precision is less of a concern than storage, consider using single for floating-point variables. Conversely, if precision is the most important criterion, use double.
Variant (variant data type) variables in VBA can store numbers by storing them as integer, long, single, or double data types within the variant structure. See Variant Declaration.