Floating Point
The Floating Point data types (REAL
and DOUBLE
) store extremely close value approximations, and are therefore recommended for values that tend to be inexact, such as Scientific Notation. While Floating Point generally runs faster than Numeric, it has a lower precision of 9
(REAL
) or 17
(DOUBLE
) compared to Numeric’s 38
. For operations that require a higher level of precision, using Numeric is recommended.
The floating point representation is based on IEEE 754.
Floating Point Types
The following table describes the Floating Point data types.
Name |
Details |
Data Size (Not Null, Uncompressed) |
Example |
---|---|---|---|
|
Single precision floating point (inexact) |
4 bytes |
|
|
Double precision floating point (inexact) |
8 bytes |
|
The following table shows information relevant to the Floating Point data types.
Aliases |
Syntax |
Data Size (Not Null, Uncompressed) |
---|---|---|
|
A double precision floating point can be entered as a regular literal, such as |
Floating point types are either 4 or 8 bytes, but size could be lower after compression. |
Floating Point Examples
The following are examples of the Floating Point syntax:
CREATE TABLE cool_numbers (a REAL NOT NULL, b DOUBLE);
INSERT INTO cool_numbers VALUES (1,2), (3.14159265358979, 2.718281828459);
SELECT * FROM cool_numbers;
1.0,2.0
3.1415927,2.718281828459
Note
Most SQL clients control display precision of floating point numbers, and values may appear differently in some clients.
Floating Point Casts and Conversions
The following table shows the possible Floating Point value conversions:
Type |
Details |
---|---|
|
|
|
|
Note
As shown in the above examples, casting real
to int
rounds down.