📚 College Credit Guide ✓ UPI Study 🕐 10 min read

What Are Floating-Point Types In SQL?

This article explains how REAL, FLOAT, and DOUBLE store approximate decimal values in SQL, why precision can slip, and when to use exact numeric types instead.

US
UPI Study Team Member
📅 August 07, 2026
📖 10 min read
US
About the Author
The UPI Study team works directly with students on credit transfer, degree planning, and course selection. We've helped thousands of students figure out what counts toward their degree and how to finish faster without paying more than they have to. This post is written the way we'd explain it to you directly.
🦉

Floating-point types in SQL store decimal values as approximations, not perfect copies, and that matters any time you compare, sum, or sort numbers. REAL, FLOAT, and DOUBLE help database systems handle wide ranges of values with less storage, but they trade away exact decimal precision. That tradeoff matters in database programming because a value like 0.1 can come back as a close neighbor, not the exact number you typed. If you are learning SQL in a database programming course, this topic shows up fast. You might see a lab with sensor readings, game scores, or lab measurements, and then watch a query return 0.3000000004 instead of 0.3. That does not mean SQL broke. It means the database stored the number in binary form, and binary does not map cleanly to every decimal fraction. Students get tripped up here because floating-point types look simple on the surface. They are not. REAL, FLOAT, and DOUBLE help when you need speed, range, and smaller storage, but they can surprise you in money columns, equality checks, and totals. Once you see how they work, the behavior starts to make sense instead of feeling random.

Database Programming
College credit · ACE & NCCRS reviewed · self-paced
View course
Close-up of a computer screen displaying programming code in a dark environment — UPI Study

What Do Floating-Point Types Store In SQL?

FLOAT, REAL, and DOUBLE store approximate decimal values in SQL by using binary floating-point, which gives you a wide range and fast math, not perfect decimal spelling. In database programming, that design lets a 4-byte or 8-byte column hold values like 3.14159, 0.125, or 9.8e6 without wasting space on exact decimal bookkeeping.

The catch: They do not store every decimal exactly, and that surprises students in the first week of a database programming course more than almost anything else.

REAL usually means single precision, FLOAT often means adjustable precision, and DOUBLE usually means double precision. The names sound clean, but SQL engines do not all treat them the same way. MySQL, PostgreSQL, SQL Server, and Oracle each have their own rules, so the type name matters less than the idea behind it: approximate storage with a bigger range than fixed decimal types.

That is why floating-point types exist at all. A system that tracks weather readings from 10,000 sensors or game physics at 60 frames per second needs speed and range more than penny-perfect decimal values. In that setting, a 64-bit DOUBLE can store huge numbers and tiny fractions in one column, which is practical when exact decimal math would slow things down.

Students should learn this early, before they build habits around "number equals number." SQL does not always work that way. A floating-point column stores the closest value it can fit, and the database programming lesson behind that is simple: range and efficiency beat exactness here.

Why Do FLOAT, REAL, and DOUBLE Lose Precision?

FLOAT, REAL, and DOUBLE lose precision because binary floating-point cannot represent many decimal fractions exactly, so the database stores the nearest possible binary value instead. Numbers like 0.1, 0.2, and 0.3 look clean in base 10, but in base 2 they turn into repeating patterns, much like 1/3 stays endless in decimal.

A 64-bit DOUBLE gives you about 15 to 17 decimal digits of precision, while a 32-bit REAL usually gives about 6 to 7. That sounds generous, and it is for physics, graphics, and scientific data. Still, the stored value often lands just above or below the decimal you typed, and that tiny gap can show up after a calculation.

Reality check: Add 0.1 three times in SQL and you may not get a clean 0.3, because each step carries a small rounding error forward.

That drift matters when you repeat math. A query that sums 10,000 rows of tiny values can pick up small errors along the way, and the result can differ from a hand-calculated total by a hair. I like to tell students that floating-point numbers are honest but slippery. They tell the truth about approximation, not about neat decimal ideals.

The database never "forgets" on purpose. It stores the nearest value it can, then keeps doing math with that stored value. Once you see that, the weird results stop feeling magical and start feeling mechanical.

How Do REAL, FLOAT, and DOUBLE Differ?

REAL, FLOAT, and DOUBLE all sit in the same family, but they do not carry the same precision or storage cost. The exact byte size can change by database system, so SQL Server, PostgreSQL, and MySQL docs matter here, yet the tradeoff stays the same: wider range and faster storage versus exact decimal control. That is the part students need to remember in Database Programming work and in any Database Fundamentals class.

TypeTypical SizePrecisionBest Use
REAL4 bytesabout 6-7 digitssmall sensor data, graphics
FLOAT4-8 bytesdepends on declared precisiongeneral approximate values
DOUBLE8 bytesabout 15-17 digitsscientific math, large ranges
Exact numericvariesdecimal exactmoney, IDs, totals
Vendor behaviordiffers by enginecheck docsMySQL, PostgreSQL, SQL Server

DOUBLE usually wins when you need the most precision among these three, but it still stays approximate. REAL saves space, yet it can distort values sooner. FLOAT sits in the middle, and some systems let you set precision like FLOAT(24) or FLOAT(53), which changes how much detail the column keeps.

Database Programming UPI Study Course

Learn Database Programming Online for College Credit

This is one topic inside the full Database Programming course on UPI Study — a self-paced, online class that earns real college credit. Credits are ACE and NCCRS evaluated and transfer to partner colleges across the US and Canada. Courses start at $250 with no deadlines and lifetime access.

Explore on UPI Study →

When Should You Use Floating-Point Types?

Use floating-point types when your data comes from the real world and a tiny error will not break the result. A weather app that stores temperature to 0.1 degrees, a physics simulation that updates 60 times per second, or a GPS feed that shifts by 3 meters can all live with approximation. Money cannot. Student IDs cannot. Exact counts of items sold in a 12-hour shift cannot either.

Bottom line: Pick FLOAT or DOUBLE for measurement, not for anything that must match a printed receipt or a school record.

That rule saves people from ugly bugs later. A 0.01 difference might look tiny, but across 5,000 rows it can produce a result that feels off by enough to confuse users. I think DOUBLE is the safest of the three, but only when the job really wants approximation. If you need exact decimals, switch to DECIMAL or NUMERIC and move on.

How Do Floating-Point Columns Affect Queries?

A floating-point column can change how a query behaves even when the SQL text looks normal, and that catches students in their first 30 or 40 practice queries. Equality checks, joins, grouping, and totals all react to tiny stored differences.

A smart database programming habit is to compare floating-point values with tolerance, not with blind equality. That one change prevents a lot of brittle code. If your assignment uses REAL or DOUBLE, test with values like 0.1, 0.2, and 0.3, because those numbers expose the problem fast.

How Does SQL Floating-Point Compare With Exact Numbers?

FLOAT, REAL, and DOUBLE trade exact decimal storage for speed, range, and compact size, while DECIMAL and NUMERIC store digits exactly. That difference matters in a database programming course because the same query can behave differently depending on whether the column stores 12.34 as an approximation or as an exact decimal.

What this means: A floating-point column can save space and still handle huge values, but an exact numeric column gives you predictable cents, grades, and counts.

That tradeoff shows up fast in college credit work too, because many transfer-oriented computer science and database classes test whether you know which type fits which job. A lab that tracks rainfall, CPU temperature, or lab results can use DOUBLE with no drama. A table that stores tuition payments, bookstore charges, or loan balances should not.

I like exact numbers better for anything people will audit. Floating-point types feel loose by design, and that looseness is useful only when the world itself is a little fuzzy. If the answer has to match on the dot, use a decimal type and stop asking a loose type to act strict.

Frequently Asked Questions about Floating Point Types

Final Thoughts on Floating Point Types

Floating-point types in SQL make sense once you stop treating them like exact decimal bins. REAL, FLOAT, and DOUBLE all store approximations, and that one fact explains almost every surprise you see in comparisons, joins, and totals. They work well for science, sensors, graphics, and other data that already comes with a little noise. They work badly for money, IDs, and anything that needs the same answer every time. The big habit to build is simple. Ask what the number means before you pick the type. A temperature reading can tolerate a tiny gap. A tuition payment cannot. A lab value can drift by a hair and still stay useful. A grade point average or bank balance cannot. Students often waste time chasing a "bug" that is really just floating-point math doing exactly what it was built to do. That is annoying, but it also gives you a clean rule for future work: use approximate types for approximate data, and use exact types when the result must land on the same digit every time. If you are writing SQL this week, test one REAL column and one DECIMAL column with 0.1, 0.2, and 0.3, then watch how each one behaves.

How UPI Study credits actually work

Ready to Earn College Credit?

ACE & NCCRS approved · Self-paced · Transfer to colleges · $250/course or $99/month

More on Database Programming
© UPI Study. This article and its educational content are solely owned by UPI Study and licensed under CC BY-NC-ND 4.0. It is not free to reuse or modify. Any citation must credit UPI Study with a direct link to this page.