···11+---
22+title: Floating-point cheat sheet for SQL
33+description: Tips for using floating-point and decimal numbers in SQL
44+---
55+66+Floating-Point Types
77+--------
88+The SQL standard defines three binary floating-point types:
99+1010+* `REAL` has implementation-dependant precision (usually maps to a hardware-supported type like IEEE 754 single or double precision)
1111+* `DOUBLE PRECISION` has implementation-dependant precision which is greater than `REAL` (usually maps to IEEE 754 double precision)
1212+* `FLOAT(N)` has at least `N` binary digits of precision, with an implementation-dependant maximum for `N`
1313+1414+The exponent range for all three types is implementation-dependant as well.
1515+1616+Decimal Types
1717+-------------
1818+The standard defines two fixed-point decimal types:
1919+2020+* `NUMERIC(M,N)` has exactly `M` total digits, `N` of them after the decimal point
2121+* `DECIMAL(M,N)` is the same as `NUMERIC(M,N)`, except that it is allowed to have more than `M` total digits
2222+2323+The maximum values of `M` and `M` are implementation-dependant. Vendors often implement the two types identically.
2424+2525+How to Round
2626+------------
2727+2828+The SQL standard defines no explicit rounding, but most vendors provide a `ROUND()` or `TRUNC()` function.
2929+3030+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.
3131+3232+3333+Resources
3434+---------
3535+* [Official ISO SQL 2008 standard (non-free)](http://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=38640)
3636+* [SQL 92 draft (free)](http://www.contrib.andrew.cmu.edu/~shadow/sql/sql1992.txt)
3737+* [MySQL numeric types](http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html)
3838+* [PostgreSQL data types](http://www.postgresql.org/docs/8.1/static/datatype.html)
3939+* [MS SQL Server data types](http://msdn.microsoft.com/en-US/library/ms187752%28v=SQL.90%29.aspx)