Approximate numbers: FLOAT and SMALLFLOAT
In scientific, engineering, and statistical applications, numbers are often known to only a few digits of accuracy, and the magnitude of a number is as important as its exact digits.
Floating-point data types are designed for these kinds of applications.
They can represent any numeric quantity, fractional or whole, over
a wide range of magnitudes from the cosmic to the microscopic. They
can easily represent both the average distance from the earth to the
sun (1.5 x 1011 meters) or Planck's constant (6.626 x 10-34 joule-seconds).
For example,
CREATE TABLE t1 (f FLOAT);
INSERT INTO t1 VALUES (0.00000000000000000000000000000000000001);
INSERT INTO t1 VALUES (1.5e11);
INSERT INTO t1 VALUES (6.626196e-34);
Two sizes of floating-point data types exist. The FLOAT type is a double-precision, binary floating-point number as implemented in the C language on your computer. A FLOAT data type value usually takes up 8 bytes. The SMALLFLOAT (also known as REAL) data type is a single-precision, binary floating-point number that usually takes up 4 bytes. The main difference between the two data types is their precision.
Floating-point numbers have the following advantages:
- They store very large and very small numbers, including fractional ones.
- They represent numbers compactly in 4 or 8 bytes.
- Arithmetic functions such as AVG, MIN, and sort comparisons are efficient on these data types.
The main disadvantage of floating-point numbers is that digits outside their range of precision are treated as zeros.