Floating-point types are fixed-length, non-precise numeric types. The value range and precision depend on the type length, precision, and scale, and whether it is unsigned.
Precision and scale represent the maximum total number of decimal digits and the maximum number of decimal digits, respectively. The maximum number of integer digits is equal to the precision minus the scale. The maximum precision is 255 (scale can only be 0), and the maximum scale is 30.
Note
The precision of floating-point types is only the theoretical value specified by the IEEE standard. The actual precision may vary slightly due to hardware or operating system limitations.
The following table shows the storage length and value range of floating-point types when precision and scale are not specified.
| Type | Length (bytes) | Value range | Precision |
|---|---|---|---|
FLOAT |
4 | [-3.402823466E+38, -1.175494351E-38], 0, and [1.175494351E-38, 3.402823466E+38] | 7 digits |
DOUBLE |
8 | [-1.7976931348623157E+308, -2.2250738585072014E-308], 0, and [2.2250738585072014E-308, 1.7976931348623157E+308] | 15 digits |
If precision and scale are specified, the value range is determined in the same way as for fixed-point types.
FLOAT
FLOAT is used to represent a small (single-precision) floating-point number. The syntax is as follows:
FLOAT[(M,D)] [UNSIGNED] [ZEROFILL]
M is the total number of digits that can be stored, and D is the number of digits after the decimal point. If M and D are omitted, the value is stored within the hardware limit. Single-precision floating-point numbers are accurate to approximately 7 decimal places.
If you specify ZEROFILL for a numeric column, OceanBase Database automatically adds the UNSIGNED attribute to the column. If you specify UNSIGNED, negative values are not allowed.
Note
FLOAT(M,D) is an outdated syntax and is not recommended for use.
FLOAT also supports the following syntax:
FLOAT(p) [UNSIGNED] [ZEROFILL]
p specifies the precision in bits, but is used only to determine whether the result data type is FLOAT or DOUBLE. If p is 0 to 24, the data type becomes FLOAT without M or D values; if p is 25 to 53, the data type becomes DOUBLE without M or D values. The range of the result column is the same as the single-precision FLOAT or double-precision DOUBLE data types described earlier in this section.
DOUBLE
DOUBLE is used to represent a normal-sized (double-precision) floating-point number. The syntax is as follows:
DOUBLE[(M,D)] [UNSIGNED] [ZEROFILL]
M is the total number of digits that can be stored, and D is the number of digits after the decimal point. If M and D are omitted, the value is stored within the hardware limit. Double-precision floating-point numbers are accurate to approximately 15 decimal places.
If you specify ZEROFILL for a numeric column, OceanBase Database automatically adds the UNSIGNED attribute to the column. If you specify UNSIGNED, negative values are not allowed.
Note
DOUBLE[(M,D)] is an outdated MySQL syntax and is not recommended for use. If you need precise searches, we recommend that you use the DECIMAL type.
DOUBLE PRECISION
DOUBLE PRECISION is a synonym for DOUBLE. The syntax is as follows:
DOUBLE PRECISION[(M,D)] [UNSIGNED] [ZEROFILL], REAL[(M,D)] [UNSIGNED] [ZEROFILL]
Note
Binary floating-point numbers do not support special values such as infinity and NaN for now.
