### Floating Point Numbers

#### Floating Point Arithmetic:

In floating point arithmetic, you peak an error margin on your relative error, imagine you want all your calculation to be correct with less than %1 error with respect to the original number (if your original number is 300, all answers between 297 and 303 will be considered as correct answers).

Then again you will need to decide how big your numbers gonna be. Imagine you want numbers be as big as 1010010100.

In floating point arithmetic you write numbers in scientific notation (0.DDDDDD*10+-pp0.DDDDDD*10+-pp) where numbers of 'D's will determine margin on relative error and number of 'p's will determine how big the number can be.

Here multiplication and division are easy. In you just multiply/divide the floating parts and then add/subtract powers (In Division you have an extra step which is making sure that the floating part does not start with a zero).

In order to add or subtract you need to make sure that both numbers have the same power, so you have to shift the smaller number. Then you will do the addition/subtraction in the normal way and write the result in the scientific notation.

#### The Floating-Point Data Types

Microsoft Visual Basic for Applications (VBA) provides two floating-point data types, Single and Double. The Single data type requires 4 bytes of memory and can store negative values between -3.402823 x 1038 and -1.401298 x 10-45 and positive values between 1.401298 x 10-45 and 3.402823 x 1038. The Double data type requires 8 bytes of memory and can store negative values between -1.79769313486232 x 10308 and -4.94065645841247 x 10-324 and positive values between 4.94065645841247 x 10-324 and 1.79769313486232 x 10308.

The Single and Double data types are very precise, that is, they make it possible for you to specify extremely small or large numbers. However, these data types are not very accurate because they use floating-point mathematics. Floating-point mathematics has an inherent limitation in that it uses binary digits to represent decimals. Not all the numbers within the range available to the Single or Double data type can be represented exactly in binary form, so they are rounded. Also, some numbers cannot be represented exactly with any finite number of digits, pi, for example, or the decimal resulting from 1/3.

Because of these limitations to floating-point mathematics, you might encounter rounding errors when you perform operations on floating-point numbers. Compared to the size of the value you are working with, the rounding error will be very small. If you do not require absolute accuracy and can afford relatively small rounding errors, the floating-point data types are ideal for representing very small or very large values. On the other hand, if your values must be accurate - for example, if you are working with money values - you should consider one of the scaled integer data types.

© 2022 Better Solutions Limited. All Rights Reserved. © 2022 Better Solutions Limited TopPrevNext