Understanding the Floating-Point Calculator
This tool converts a decimal number into the binary format computers actually use to store it: IEEE 754 floating-point. Nearly every modern language — JavaScript, Python, C, Java — represents non-integer numbers this way, and it explains classic surprises like 0.1 + 0.2 not quite equaling 0.3. Enter a decimal value and pick single (32-bit) or double (64-bit) precision to see the sign, exponent, and mantissa bits, the raw bits in hex, the exact decimal value that gets stored, and how far that stored value drifts from what you typed.
The IEEE 754 formula
A normal (non-zero, non-subnormal) IEEE 754 number is built from three fields and reconstructed as:
- value = (-1)sign × 1.mantissa2 × 2(exponent − bias)
- Sign bit: 1 bit — 0 for positive, 1 for negative.
- Exponent: stored with a bias so it never needs its own sign. Single precision uses 8 bits with bias 127; double precision uses 11 bits with bias 1023.
- Mantissa (significand): the fractional bits after an implied leading 1. Single precision stores 23 mantissa bits; double precision stores 52.
To encode a value, the calculator normalizes it to the form 1.xxxxx × 2e, biases the exponent, and rounds the fraction to fit the available mantissa bits — that rounding step is exactly where precision gets lost.
Single vs. double precision
- Single precision (binary32): 1 + 8 + 23 = 32 bits total, roughly 7 significant decimal digits of precision, exponent range about 1.2×10-38 to 3.4×1038.
- Double precision (binary64): 1 + 11 + 52 = 64 bits total, roughly 15–17 significant decimal digits, exponent range about 2.2×10-308 to 1.8×10308.
JavaScript numbers are natively double precision, so when you select the 64-bit format the "stored value" and "representation error" simply reflect what your browser already computed when it parsed your input — the error is effectively zero at that point. Switching to 32-bit shows the extra rounding that happens when a double gets squeezed into a float, which is the more visible and more common source of floating-point surprises.
Why decimals like 0.1 aren't exact
Binary floating-point can only represent a decimal exactly if it is a finite sum of powers of two (0.5, 0.25, 0.125, and combinations of them). Numbers like 0.1 or 0.3 need an infinitely repeating binary fraction, the same way 1/3 repeats forever as 0.333... in decimal. IEEE 754 rounds these to the nearest representable value, which is why 0.1 is actually stored as 0.1000000000000000055511151231257827021181583404541015625 in double precision — a number so close to 0.1 that display routines round it back to "0.1" when printed.