DOUBLE
The 64-bit double-precision floating-point type (DOUBLE) follows the IEEE 754 standard and is used to store real numbers. It can represent very large or very small values, with an effective precision of approximately 15 to 17 decimal digits.
Syntax
Value Range
- Maximum positive value: approximately 1.7976931348623157 x 10308
- Minimum positive value (non-zero): approximately 4.9 x 10-324
- Literal suffix:
D(e.g.,1D,-6.5D)
Examples
-
Use a DOUBLE literal suffix:
Returns:
1 -
Cast an integer to DOUBLE:
Returns:
-6 -
Scientific notation representation:
Returns:
19971400000000 -
Cast a string to DOUBLE:
Returns:
123.456 -
Add two DOUBLE values:
Returns:
802.366 -
Compare two DOUBLE values:
Returns:
true -
Calculate square root:
Returns:
4 -
NULL value handling:
Returns:
NULL -
Precision loss example (difference between DOUBLE and DECIMAL):
Returns:
0.30000000000000004(floating-point precision error)Compare with DECIMAL:
Returns:
0.3(exact calculation)
Notes
- DOUBLE is an approximate numeric type and is not suitable for scenarios requiring exact calculations (such as financial amounts). For exact calculations, use the
DECIMALtype instead. - Comparisons of floating-point numbers may produce unexpected results due to precision errors. Avoid using
=directly to compare two DOUBLE values. - Values exceeding the representable range will return
Infinityor-Infinity; invalid operations (e.g., 0/0) will returnNaN. - CAST conversion returns NULL on failure.
