Unit Converter: how it works and how to build one
Length, weight, temperature, area, volume, speed, data and more. This guide explains what happens behind the button and shows the code, so you can build your own.
What it does
Convert between metric, imperial and Indian units (like square feet, gaj and bigha for land) across 10 categories. Every unit in the category is shown at once so you can compare.
When to use it
- Recipes
- Land measures like gaj and bigha
- Data sizes (MB vs MiB)
How to use it
- Pick a category.
- Type a value and choose its unit.
- Read every conversion.
Try it free in your browser, nothing is uploaded: https://eskillsfy.com/tools/unit-converter
How it works
Each category picks one base unit (metre, kilogram, litre…) and stores every other unit as a factor of it. Converting is value × factor(from) ÷ factor(to), so adding a new unit is one line.
Temperature is the exception, because the scales have different zero points; it converts through Celsius with formulas instead of factors.
Build it yourself
Here is the core of the tool. It has no dependencies unless noted, so you can paste it into any TypeScript or JavaScript project.
units.ts (ts)
const LENGTH: Record<string, number> = { mm: 0.001, cm: 0.01, m: 1, km: 1000, in: 0.0254, ft: 0.3048, mi: 1609.344 };
export const convert = (v: number, from: string, to: string, table = LENGTH) => (v * table[from]) / table[to];
export const cToF = (c: number) => c * 9 / 5 + 32;
export const fToC = (f: number) => (f - 32) * 5 / 9;
convert(5, "ft", "cm"); // 152.4
Make it production-ready
- Show every unit at once.
- Format very large and small numbers in exponent form.
Questions
How big is a bigha?
It varies by state. This tool uses the common 27,000 sq ft (UP/Rajasthan) value, so check your local measure.
Free, runs in your browser, nothing is uploaded.