![]() Previous |
![]() Next |
All decimal data is converted to floating point format, both for storing and for calculations. In floating point format, a number is represented by means of a mantissa and an exponent. The mantissa and the exponent are stored as binary numbers. The mantissa is a binary fraction which, when multiplied by a number equal to 2 raised to the exponent, produces a number that equals or closely approximates the original decimal number.
Because there is not always an exact binary representation for a fractional decimal number, just as there is not an exact representation for the decimal value of 1/3, fractional parts of decimal numbers cannot always be represented exactly as binary fractions. Arithmetic operations on floating point numbers can result in further approximations, and the inaccuracy gradually increases with the number of operations. In addition to the approximation factor, the available number of significant digits affects the exactness of the result.
For all of these reasons, a result computed by the TOTAL, AVERAGE, or other aggregation functions on a DECIMAL
or SHORTDECIMAL
variable can differ in the least significant digits from a result you compute by hand. Because the SHORTDECIMAL
data type provides a maximum of only seven significant digits, you see more of these differences with SHORTDECIMAL
data. Therefore, you might want to use the NUMBER
data type when accuracy is more important than computational speed, such as variables that contain currency amounts.
Another result of the fact that some fractional decimal numbers cannot be exactly represented by binary fractions is that for such numbers, the DECIMAL
data type offers a different and closer approximation than the SHORTDECIMAL
data type, because it has more significant digits. This can lead to problems when SHORTDECIMAL
and DECIMAL
data types are mixed in a comparison expression. For information on how to handle such comparisons, see "Boolean Expressions" .