Single
This is an abbreviation for Single Precision Floating Point.
This can support 7 significant figures with 6 decimal places.
This data type uses 4 bytes
The default value is 0.
Dim mySingle As Single
Possible Values
The Single data type can contain any numbers in the following ranges:
Negative numbers: -3.402823 E+38 to -1.401298 E-45
Positive numbers: 1.401298 E-45 to 3.402823 E+38
Adding Two Numbers
Declare two variables with the value (8,388,608) and add them together.
Dim mySingle1 As Single
Dim mySingle2 As Single
Dim myResult As Single
mySingle1 = 8388608
mySingle2 = 8388608
myResult = mySingle1 + mySingle2
Debug.Print myResult ' = 1.677722E+07
Rounding Errors
You should always use the Double data type instead because this data type introduces rounding errors.
Declare two variables with the value (1,234.5678) and add them together.
The answer is actually 2469.1356.
Dim mySingle1 As Single
Dim mySingle2 As Single
Dim myResult As Single
mySingle1 = 1234.5678
mySingle2 = 1234.5678
myResult = mySingle1 + mySingle2
Debug.Print myResult ' = 2469.135
Conversion Function
The CSNG function returns an expression converted to a Single data type.
© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext