FLOAT
The 32-bit single-precision floating-point type (FLOAT) follows the IEEE 754 standard, with an effective precision of approximately 6 to 7 decimal digits. It is suitable for storing real numbers that do not require exact computation. For exact computation scenarios, use DECIMAL.
Syntax
REAL is an alias for FLOAT, provided for compatibility with migration scripts from other databases. Aliases are immediately converted to the canonical type during parsing; see Type Aliases for details.
Value Range
- Maximum positive value: approximately 3.4028235 × 10³⁸
- Minimum positive value (non-zero): approximately 1.4 × 10⁻⁴⁵
- Literal suffix:
F(e.g.,1.5F,-3.2F)
Examples
-
Using the FLOAT literal suffix:
Returns:
1.5 -
Convert an integer to FLOAT:
Returns:
6.0 -
Convert a string to FLOAT:
Returns:
3.14 -
Precision loss example:
Returns:
1234568.0(exceeds 7 significant digits, precision loss occurs) -
NULL value handling:
Returns:
NULL
Type Selection Guide
| Scenario | Recommended Type | Reason |
|---|---|---|
| Financial amounts, exact computation | DECIMAL | Exact decimal, no floating-point error |
| Scientific computation, high-precision statistics | DOUBLE | Precision ~15-17 digits, twice that of FLOAT |
| ML feature values, vector elements | FLOAT | Sufficient precision (6-7 digits), half the storage of DOUBLE |
| Compatibility with other systems | FLOAT / REAL | REAL is an alias for FLOAT |
FLOAT vs DOUBLE precision comparison (measured):
Notes
- FLOAT is an approximate numeric type with effective precision of about 6-7 digits. It is not suitable for scenarios requiring exact computation such as financial amounts; use
DECIMALinstead. - Avoid using
=to directly compare two FLOAT values; precision errors may produce unexpected results. - Arithmetic overflow returns
Infinityor-Infinity; invalid operations such assqrt(-1)returnNaN. - CAST of an invalid string returns NULL.
