Floating-point cheat sheet for SQL

Floating-Point Types

The SQL standard defines three binary floating-point types:

The exponent range for all three types is implementation-dependant as well.

Decimal Types

The standard defines two fixed-point decimal types:

The maximum values of M and M are implementation-dependant. Vendors often implement the two types identically.

How to Round

The SQL standard defines no explicit rounding, but most vendors provide a ROUND() or TRUNC() function.

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.

Resources

© Published at floating-point-gui.de under the Creative Commons Attribution License (BY)

Fork me on GitHub