Floating-point cheat sheet for SQL
The SQL standard defines three binary floating-point types:
REALhas implementation-dependent precision (usually maps to a hardware-supported type like IEEE 754 single or double precision)
DOUBLE PRECISIONhas implementation-dependent precision which is greater than
REAL(usually maps to IEEE 754 double precision)
FLOAT(N)has at least
Nbinary digits of precision, with an implementation-dependent maximum for
The exponent range for all three types is implementation-dependent as well.
The standard defines two fixed-point decimal types:
Nof them after the decimal point
DECIMAL(M,N)is the same as
NUMERIC(M,N), except that it is allowed to have more than
The maximum values of
M are implementation-dependent. Vendors often implement the two types identically.
How to Round
The SQL standard defines no explicit rounding, but most vendors provide a
However, it usually makes little sense to round within the database, since its job is storing data, while rounding is an aspect of displaying data, and should therefore be done by the code in the presentation layer.