Unit Converter
Convert between units of length, weight, temperature, volume, area, and speed. Live conversion.
Unit conversion as a source of defects
Converting between units looks like arithmetic and behaves like a minefield in software. A product that shows weight in kilograms to one user and pounds to another has to decide what it stores, when it converts, and how it rounds, and each of those three decisions has a wrong answer that ships regularly.
The rule that avoids most of it is the same as for dates: store one canonical unit, convert only for display, and never convert a stored value in place. A system that converts on save loses precision every time a user edits a record, so a weight that was entered once as 70 kg can drift after a few round trips through pounds.
Temperature is not like the others
Most conversions are a simple multiplication: a metre is always 3.28084 feet, and zero metres is zero feet. Temperature scales have different zero points, so Celsius to Fahrenheit requires a multiplication and an offset. Code written generically as a single conversion factor produces a plausible-looking wrong answer for temperature, and it is one of the most common conversion bugs there is.
Test values that expose it: 0 °C is 32 °F, −40 is the same in both scales, and 100 °C is 212 °F. If a converter returns 0 °F for 0 °C, it is applying a factor with no offset.
Data sizes, and the two definitions of a kilobyte
Storage is where two standards collide. The decimal definition makes a kilobyte 1,000 bytes; the binary definition makes it 1,024, properly called a kibibyte. Drive manufacturers use decimal, most operating systems report binary, and the gap widens with scale: about 2.4% at kilobytes and roughly 10% at terabytes. That is why a drive sold as one terabyte shows as about 931 gigabytes.
For testing, this matters wherever a limit is expressed in bytes. An upload capped at 5 MB accepts a different file depending on which definition the validator uses, so a file sitting between the two thresholds is an excellent boundary test case.
Rounding, and why totals stop adding up
Converted values are almost never exact, so something has to round. Two questions decide whether the result is defensible: how many decimal places, and whether rounding happens before or after any arithmetic. Rounding each line of an order and then summing gives a different total from summing and then rounding, and the difference is visible to a customer.
Worth checking in any product that converts: a value that rounds to zero at the chosen precision, a value exactly on a half boundary, implementations differ on whether 2.5 rounds to 2 or 3, and a round trip, where converting to another unit and back should return the original value within a stated tolerance.
Test values worth reusing
| Input | Why it is interesting |
|---|---|
| 0 | Exposes conversions that wrongly apply an offset, and ones that wrongly omit it |
| Negative values | Valid for temperature, usually invalid for length or weight: is it rejected? |
| −40 °C | The single point where Celsius and Fahrenheit agree |
| Very large values | Overflow and scientific-notation formatting |
| Very small values | Rounds to zero, which may be displayed as an empty or meaningless result |
| A value on a half boundary | Reveals the rounding mode in use |
| Locale-formatted input | A comma decimal separator, as used across most of Europe |
The last one is underrated. In much of the world a decimal is written with a comma, so a field that only accepts a dot rejects correctly formatted input from a large population, and worse, a parser that strips the comma as a thousands separator reads 1,5 as fifteen.
Frequently asked questions
Is a kilobyte 1000 or 1024 bytes?
Both definitions are in use. The decimal kilobyte is 1,000 bytes and is what storage manufacturers quote; 1,024 bytes is properly a kibibyte and is what most operating systems report. The discrepancy grows with scale, which is why a one-terabyte drive shows as roughly 931 gigabytes.
Why does converting a value and converting it back not return the original?
Because each conversion rounds. The remedy is to store one canonical unit and convert only for display, never converting a stored value in place. A round-trip test with a stated tolerance is a good way to prove a system does this correctly.
Why is temperature conversion different from other units?
Because temperature scales have different zero points, so the conversion needs an offset as well as a factor. Generic conversion code written as a single multiplier returns a plausible but wrong answer. Testing 0 °C, which must give 32 °F, exposes it immediately.
What rounding should a converted value use?
Whatever the specification says, stated explicitly, including the number of decimal places and the behaviour on a half boundary. The important rule is to round once at the end rather than at each intermediate step, because rounding line by line and then summing produces a different total.
Should a converter accept a comma as a decimal separator?
For an international audience, yes. A comma decimal is standard in much of Europe and elsewhere. A parser that treats it as a thousands separator turns 1,5 into 15, which is a silent data corruption rather than a validation error.
Does the conversion happen on a server?
No, it runs in your browser, so values taken from an internal system are not transmitted anywhere.