Skip to main content
CockroachDB supports various inexact, floating-point number with up to 17 digits of decimal precision. They are handled internally using the standard double-precision (64-bit binary-encoded) IEEE754 format.

Names and Aliases

NameAliases
FLOATNone
REALFLOAT4
DOUBLE PRECISIONFLOAT8

Syntax

A constant value of type FLOAT can be entered as a . For example: 1.414 or -1234. The special IEEE754 values for positive infinity, negative infinity and NaN (Not-a-Number) cannot be entered using numeric literals directly and must be converted using an or an from a string literal instead. The following values are recognized:
SyntaxValue
inf, infinity, +inf, +infinity+∞
-inf, -infinity-∞
nanNaN (Not-a-Number)
For example:
  • FLOAT '+Inf'
  • '-Inf'::FLOAT
  • CAST('NaN' AS FLOAT)

Size

A FLOAT column supports values up to 8 bytes in width, but the total storage size is likely to be larger due to CockroachDB metadata.

Examples

Supported casting and conversion

FLOAT values can be to any of the following data types:
TypeDetails
INTRounds the float to the nearest integer. If equidistant to two integers, rounds to the even integer. See Cast FLOAT to INT.
DECIMALCauses an error to be reported if the value is NaN or +/- Inf.
BOOL0 converts to false; any other value converts to true.
STRING

Cast FLOAT to INT

If you cast a float to an integer, it is rounded to the nearest integer. If it is equidistant to two integers, it is rounded to the even integer. For example:

See also