What Is a Floating-Point Number?
How computers handle decimals, and why 0.1 plus 0.2 isn't quite 0.3.
What a floating-point number is
A floating-point number is the way computers represent numbers that have a decimal point, such as 3.14, 0.5, or 9.99. Unlike integers, which are whole numbers, floating-point numbers can represent fractions and measurements. The name 'floating point' refers to how the decimal point can 'float' to represent both very large and very small numbers efficiently. This type is essential whenever a program needs to work with values that are not whole numbers.
Why they are needed
Many real-world quantities are not whole numbers. Prices, temperatures, distances, weights, and scientific measurements all involve fractions. Integers cannot represent these; you need a type that handles decimals. Floating-point numbers fill that role, letting programs work with the continuous, fractional values that appear throughout science, finance, graphics, and everyday calculations. Whenever precision beyond whole numbers is required, floating-point is typically the tool programmers reach for.
The precision problem
Floating-point numbers have a famous quirk: they are not always perfectly precise. Because computers store them in binary with a limited number of digits, some decimal values cannot be represented exactly, leading to tiny rounding errors. A classic example is that adding 0.1 and 0.2 can give a result very slightly off from 0.3. These errors are usually minuscule, but they are real, and they surprise many people learning about how computers handle numbers.
Why the imprecision happens
The imprecision comes from representing decimal fractions in binary. Just as one-third cannot be written exactly as a finite decimal (0.3333...), many ordinary decimals cannot be written exactly in binary with limited digits. The computer stores the closest value it can, which is extremely close but not always exact. This is a fundamental characteristic of floating-point math, not a bug, and understanding it explains those occasionally odd results.
When precision matters
For most purposes, tiny floating-point errors do not matter. But in some situations, especially money, they can cause problems: fractions of a cent can add up or cause rounding disputes. For this reason, financial software often uses special techniques or data types designed for exact decimal math instead of standard floating-point. Knowing when floating-point's small imprecisions matter, and when they do not, is a practical and important skill for programmers.
Why it matters
Floating-point numbers are how computers handle the vast world of non-whole numbers, from prices to scientific data. Understanding them, especially the surprising fact that they can be slightly imprecise, helps you avoid subtle bugs and make smart choices about representing numbers in code. It is one of those concepts that explains puzzling behavior many programmers encounter, and knowing it marks a real step forward in understanding how computers work with numbers.
Related on Skillo
See also: What is an integer in programming?, What is binary code? Explained simply.
Sources
Published date reflects the original event date (2024-07-02). This article is original Skillo editorial written from the sources above; facts were verified in September 2026.
Written by
Skillo Staff
0 Comments
Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.