The Unit Converter That Lies at the Sixth Decimal
Unit conversion looks like arithmetic until you read the formatting line. A walkthrough of parseFloat, affine temperature scales, six-decimal rounding and the inputs that quietly turn into zero — with the exact numbers each case produces.
What this guide covers
- 1. What the shared converter actually does
- 2. parseFloat is much more permissive than a number field
- 3. Six decimals hide error as often as they reveal it
- 4. Temperature is affine, not proportional
- 5. When a browser converter is the wrong instrument
- 6. A short checklist for anyone building one
- 7. Frequently asked questions
- 8. The one-line version
A unit converter is the kind of tool nobody expects to be interesting. Type a number, pick two units, get a number back. Yet the answer you see is the product of three separate decisions — how the input is parsed, how the conversion is composed, and how the result is rounded — and any one of them can change the last digits or, for very small values, erase the answer entirely.
The Length Converter, Weight Converter, Temperature Converter and their siblings on this site all share one small component. Reading it closely is a compact lesson in why 'just multiply by a constant' is not quite enough.
What the shared converter actually does
Each unit supplies two functions: `toBase(v)` converts into a canonical base unit, and `fromBase(v)` converts out of it. The converter parses the input with `parseFloat`, calls `units[from].toBase(v)`, then `units[to].fromBase(base)`. Finally it formats:
That last line is doing more work than it appears to. It is the reason `1 mile` displays as `1.609344` instead of `1.609344000`, and also the reason a value of `1e-9` metres converted to kilometres displays as 0 rather than `0.000000001`. Six decimal places is a display decision, and at sufficiently small magnitudes a display decision becomes a data-loss decision.
parseFloat is much more permissive than a number field
The input is a plain text field passed to `parseFloat`. That function reads the longest numeric prefix and ignores the rest. Feed it `12abc` and the converter computes with 12, silently. Feed it `1,000` — a perfectly normal way to write a thousand in English — and it computes with 1, because the comma ends the parse. A leading `+`, surrounding whitespace and exponent notation are all accepted.
This is not a defect so much as a contract: `parseFloat` is designed for parsing CSS-like numeric prefixes, not for validating user input. When the value matters, validate before converting — use `Number(value)` with an explicit emptiness check, or a regex that rejects trailing junk and locale separators. The tool's own hint does not claim to validate; it just converts what it can read.
Six decimals hide error as often as they reveal it
Binary floating point cannot represent most decimal fractions exactly. `0.1 + 0.2` evaluates to `0.30000000000000004`, not `0.3`. Run that sum through the converter's formatting function and the output is `0.3`, because `toFixed(6)` rounds the excess away. The rounding is doing double duty: it presents a sane number of digits *and* accidentally sanitises the artefact of binary arithmetic.
That is convenient for a quick conversion and dangerous if you treat the displayed string as an exact value. Consider the opposite end: `123456789.123456` survives `toFixed(6)` intact, so the converter will happily display fifteen significant digits — far more precision than a `double` can meaningfully guarantee, and far more than any physical measurement supports. Six *decimal places* is not six *significant figures*; for large numbers it implies precision that is not there, and for small numbers it throws away precision that was.
Very large results take a different path. `1e21` satisfies `out % 1 === 0`, so the integer branch calls `toString()` and the display becomes `1e+21`. That is valid JavaScript number formatting, but a user expecting a unit value may not recognise it as a quantity. Exact integers above `Number.MAX_SAFE_INTEGER` (2⁵³ − 1) cannot be represented reliably at all, regardless of formatting.
Temperature is affine, not proportional
Length, weight and area conversions are pure scaling: `toBase(v) = v * k`, `fromBase(v) = v / k`. Temperature is different. The Temperature Converter uses Celsius as its base and defines Fahrenheit as `toBase(v) = (v - 32) * 5/9`, `fromBase(v) = v * 9/5 + 32`, with Kelvin offset by 273.15. These are affine transforms with a translation, not ratios.
That distinction matters the moment anyone tries to reason about *differences*. A difference of 10 °C is 18 °F, but 10 °C as an absolute reading is 50 °F. You cannot convert a temperature interval with the same formula as a temperature point. The shared `toBase`/`fromBase` structure handles point conversions correctly because each unit carries its own offset; it would be wrong to reuse those functions for a delta. Kelvin's offset also means the scale has a hard floor at absolute zero, which the converter does not enforce — a negative Kelvin input will produce a number, not a warning.
There is also a pleasing numerical accident worth checking rather than assuming: converting 98.6 °F to Celsius through `(98.6 - 32) * 5/9` yields exactly `37` in IEEE 754 double arithmetic, and converting back gives `98.6`. Most values are not so tidy. Chains of conversions — metres to feet to inches to centimetres — accumulate small errors at every step, because each intermediate result is rounded to 53 bits before the next multiplication.
When a browser converter is the wrong instrument
- Financial and legal quantities. Currency conversion needs decimal arithmetic with an explicit rounding policy, not binary floats and a `toFixed`. Use a decimal library or integer minor units.
- Scientific or engineering values with stated uncertainty. Six fixed decimals discard significant digits on small values and invent them on large ones. Preserve the original measurement and its error bound.
- Very small or very large magnitudes. Below about `1e-6` in the target unit the current formatter rounds to zero; above `1e21` JavaScript switches to exponent notation. Neither is a conversion error, but both are presentation traps.
- Anything that must round-trip exactly. A → B → A is not guaranteed to return the original string. If the pipeline needs that property, use rational or decimal representations throughout.
- Bulk transformation. A browser tool is for one value at a time. Converting thousands of rows belongs in a script with an auditable unit library.
For quick sanity checks the surrounding tools help: the File Size Converter deals with the related but distinct confusion between decimal (1000-based) and binary (1024-based) units, and the Time Converter is a reminder that durations and instants are different objects — the same conceptual boundary the Timestamp Converter article covers in more depth.
A short checklist for anyone building one
- Validate the input explicitly. Reject trailing characters and locale separators instead of relying on `parseFloat`.
- Format with significant digits, not fixed decimals, and let the user choose the precision.
- Keep the unrounded value internally; round only for display.
- Separate point conversions from interval conversions, and enforce physical floors such as 0 K where they exist.
- State the conversion factors. A mile is exactly 1609.344 metres by international agreement; writing the constant in the source makes the number auditable.
Frequently asked questions
Why did my tiny value become 0? The formatter keeps six decimal places, so anything below `0.0000005` in the target unit rounds to zero. Convert to a smaller unit first.
Why did `1,000` become 1? `parseFloat` stops at the comma. Enter `1000` without a separator.
Is the temperature formula wrong for differences? The formula is for absolute readings. A 10-degree *difference* in Celsius is 18 degrees Fahrenheit; use the scale factor alone, without the 32 offset.
Why does `0.1 + 0.2` not show as `0.30000000000000004`? Six-decimal formatting rounds it away. The internal floating-point value is still the long one.
Can I rely on these numbers for money or regulated measurements? No. Use decimal arithmetic with an explicit rounding rule, and keep the original value and its uncertainty.
The one-line version
Conversion factors are exact; the surrounding float arithmetic and six-decimal formatting are not. Know which one you are looking at before you copy the number into anything that matters.
Tools run privately in your browser
Every tool referenced in this guide processes your input in the browser rather than uploading it to a server we operate, and requires no account. A typical single job stays free. Larger batches, history export, and an ad-free page are optional on Pro. A few tools load a processing engine from a CDN on first use; see the privacy policy for details. Browse the full toolbox →