SQL Keywords

SQL FLOAT

What does the SQL FLOAT data type do?

Stores approximate numeric values in floating-point format.
Sign up to get up to date news on SQL keywords
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Compatible dialects for SQL FLOAT: PostgreSQL, MySQL, SQL Server, Oracle, SQLite, Snowflake, BigQuery, MariaDB

SQL FLOAT Full Explanation

FLOAT is an ANSI-standard approximate numeric data type that stores numbers using binary scientific notation. Because the value is held as a mantissa and exponent, FLOAT can represent a very wide range of magnitudes but only with limited precision. Results are therefore subject to rounding error, and comparisons may not behave as expected when values are very close. Vendors commonly allow an optional precision parameter that determines how many binary or decimal digits of accuracy the column should try to maintain. Smaller precisions save space but reduce accuracy. If no precision is supplied, each database engine chooses a default, typically equivalent to 53 binary digits (double precision). FLOAT is ideal for scientific and engineering calculations where magnitude is more important than exactness, but it is inappropriate for monetary or other exact-value use cases. Many dialects also provide REAL (single precision) and DOUBLE PRECISION (double precision) as convenience aliases for specific FLOAT precisions.

SQL FLOAT Syntax

column_name FLOAT[(p)]

SQL FLOAT Parameters

  • p (integer) - Optional. Desired precision in binary or decimal digits, vendor-specific interpretation.

Example Queries Using SQL FLOAT

-- Define a table with FLOAT columns
CREATE TABLE sensor_readings (
    id           SERIAL PRIMARY KEY,
    temperature  FLOAT,           -- default precision
    humidity     FLOAT(24)        -- roughly 7 decimal digits of precision
);

-- Insert approximate numeric data
INSERT INTO sensor_readings (temperature, humidity)
VALUES (21.4567, 58.1234);

-- Compute an average
SELECT AVG(temperature) AS avg_temp
FROM   sensor_readings;

Expected Output Using SQL FLOAT

#VALUE!

Use Cases with SQL FLOAT

  • Storing scientific measurements where a small rounding error is acceptable
  • Holding large or very small values without consuming excessive storage
  • Performing statistical or engineering calculations that tolerate approximate results

Common Mistakes with SQL FLOAT

  • Using FLOAT for financial data that requires exact precision
  • Assuming FLOAT comparisons with = will always work as expected; prefer tolerance checks
  • Forgetting that FLOAT precision is vendor-specific and may differ across systems
  • Believing FLOAT(24) means 24 decimal digits; in many engines it means 24 binary digits (~7 decimal)

Related Topics

REAL, DOUBLE PRECISION, NUMERIC, DECIMAL, ROUND, CAST

First Introduced In

SQL-92

Frequently Asked Questions

When should I use FLOAT instead of DECIMAL?

Use FLOAT for scientific or statistical values where small rounding errors are acceptable. Choose DECIMAL for financial or other exact values.

Does FLOAT precision differ between databases?

Yes. MySQL, SQL Server, PostgreSQL, and Oracle each interpret the precision parameter differently. Always check your database documentation.

Why do equality comparisons on FLOAT sometimes fail?

Because floating-point numbers are stored in binary scientific notation, many decimal fractions cannot be represented exactly. Always compare with a tolerance.

Is FLOAT suitable for currency?

No. Currency values demand exact precision. Use DECIMAL or NUMERIC with a fixed scale instead.

Sign up to get up to date news on SQL keywords
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.
Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo

Check out other commonly used SQL Keywords!