SQL
5 min read
BEGINNER
Floating point
Quick AnswerFloating-point types represent approximate numerical values. They are useful for scientific measurements where small rounding errors are acceptable.
Core idea
Floating-point types represent approximate numerical values. They are useful for scientific measurements where small rounding errors are acceptable.
Minimal example
sql
SELECT (0.1 + 0.2) = 0.3;Expected SQLite rows:
text
0How it works
SQLite REAL uses binary64 floating point; PostgreSQL REAL and DOUBLE PRECISION have different precision. Decimal fractions such as 0.1 are not exactly representable in binary floating point. In PostgreSQL decimal literals normally use numeric arithmetic unless converted; the SQLite example is not evidence of PostgreSQL literal behavior. ABS returns absolute magnitude.
Practical example
sql
SELECT ABS((0.1 + 0.2) - 0.3) < 0.000001;Expected SQLite rows:
text
1Common mistake and practice
Avoid exact equality for approximate measurements when a tolerance is appropriate. Choose the tolerance from the measurement requirements, not arbitrarily.