Menu

MySQL FLOAT: Approximate Single-Precision Values

Updated on

MySQL FLOAT stores approximate numeric values. A plain FLOAT uses four bytes for single-precision storage; it can be useful for measurements where approximation is acceptable. Avoid it for money or other values that require exact decimal comparisons. For fixed precision and scale, use DECIMAL instead. See MySQL’s floating-point type reference.

Syntax and storage

For portable declarations, use FLOAT without a precision or digit count:

temperature FLOAT

MySQL also supports FLOAT(p), where p is a precision in bits used to select storage size and resulting type. If the intended type is DOUBLE, declare DOUBLE explicitly rather than relying on FLOAT(p) to change the result type. For maximum portability, omit a precision specification.

The older FLOAT(M,D) syntax is a nonstandard MySQL extension and is deprecated. The M and D form is not a reliable way to request decimal arithmetic; use DECIMAL(M,D) when you need an exact decimal scale. UNSIGNED for FLOAT is also deprecated in current MySQL documentation.

Example: store a measurement

CREATE TABLE sensor_readings (
    sensor_id INT NOT NULL,
    temperature_c FLOAT NOT NULL
);

INSERT INTO sensor_readings (sensor_id, temperature_c)
VALUES (1, 21.375);

When calculations or repeated updates are involved, a floating-point value may not equal the decimal text used to enter it. Do not test computed FLOAT values for exact equality. Choose a tolerance appropriate to the measurement and compare the absolute difference, or use DECIMAL if exact decimal behavior is required. MySQL’s floating-point comparison guidance demonstrates tolerance-based comparisons.

When to use FLOAT or DOUBLE

FLOAT uses less storage than DOUBLE but has less precision. Both are approximate binary floating-point types; choose based on the required range and acceptable rounding error. For exact monetary amounts, see the MySQL DECIMAL guide and the DECIMAL type reference.