IEEE 754 floating-point converter
0.1 cannot be stored exactly in binary: a 32-bit float holds 0.100000001490116…. Convert a decimal to its float32 or float64 bits, or paste hex bits to read the number inside.
A 32-bit float cannot hold 0.1 exactly: it stores 0.10000000149, a relative error of 1.5e-8.
Quick reference
Common numbers as float32 and float64 bits
| dec | float32 hex | float64 hex | float32 |
|---|---|---|---|
| 0.1 | 3DCCCCCD | 3FB999999999999A | 0.100000001 |
| 0.2 | 3E4CCCCD | 3FC999999999999A | 0.200000003 |
| 0.3 | 3E99999A | 3FD3333333333333 | 0.300000012 |
| 0.5 | 3F000000 | 3FE0000000000000 | 0.5 |
| 1 | 3F800000 | 3FF0000000000000 | 1 |
| -1 | BF800000 | BFF0000000000000 | -1 |
| 2 | 40000000 | 4000000000000000 | 2 |
| 3.14159265358979 | 40490FDB | 400921FB54442D11 | 3.14159274 |
| 10 | 41200000 | 4024000000000000 | 10 |
| 100 | 42C80000 | 4059000000000000 | 100 |
| 16777216 | 4B800000 | 4170000000000000 | 16777216 |
| 16777217 | 4B800000 | 4170000010000000 | 16777216 |
What it means
Where does it sit in the float range?
Uses round-to-nearest, as every processor does by default. The binary form shows sign, exponent and fraction separated by spaces.
Every unit
That number in every format
Good to know
Why 0.1 + 0.2 is not exactly 0.3
A floating-point number is stored as a sign, an exponent and a binary fraction. Fractions whose denominator is a power of two (0.5, 0.25, 0.375) are exact; most decimal fractions are not, because 0.1 in binary repeats forever like 1/3 in decimal. The computer keeps the nearest value it can: 0.1 becomes 0.100000001490116 in float32 and 0.1000000000000000055 in float64.
Float32 has 24 bits of precision, about 7 decimal digits, so every whole number up to 16,777,216 is exact and 16,777,217 is not. Float64 has 53 bits, about 16 digits, exact up to 9,007,199,254,740,992. Compare floats with a small tolerance instead of ==, and use integers (cents, not euros) for money.
Learn
Three things worth knowing
-
Seven and sixteen digits
Trust about 7 significant digits from a float32 and 15–16 from a float64. Integers are exact up to 16,777,216 (2²⁴) and 9,007,199,254,740,992 (2⁵³).
-
William Kahan’s standard
Before 1985 every computer rounded differently. IEEE 754, led by William Kahan, fixed the formats, the rounding and special values like infinity and NaN.
-
Comparing with ==
0.1 + 0.2 == 0.3 is false with doubles. Compare floats within a small tolerance instead.
Keep going
What people use next
Shortcuts
Popular number conversions
Background
About floating point
A float stores a number as sign × 1.fraction × 2exponent. A 32-bit float has 1 sign bit, 8 exponent bits and 23 fraction bits, about 7 significant digits; a 64-bit double has 11 and 52, about 16 digits.
Most decimal fractions have no exact binary form, so they are rounded: 0.1 is really 0.100000001490116… as a float and 0.1000000000000000055… as a double. That is why 0.1 + 0.2 is not exactly 0.3 in most programming languages.