Converters

Metric vs Imperial: A Developer's Quick Reference

A practical guide to metric and imperial unit conversions, with formulas and code examples for common measurements.

HandyUtils December 25, 2025 6 min read

Working on international projects? You'll inevitably need to convert between metric (used by most of the world) and imperial (used by the US, Liberia, and Myanmar). Here's a practical reference for developers.

The Two Systems

Metric (SI)

Based on powers of 10—clean and logical:

  • Length: meter (m)
  • Mass: gram (g), kilogram (kg)
  • Volume: liter (L)
  • Temperature: Celsius (°C)

Prefixes are consistent: kilo = 1000, centi = 1/100, milli = 1/1000

Imperial/US Customary

Based on... historical reasons:

  • Length: inch, foot, yard, mile
  • Mass: ounce, pound
  • Volume: cup, pint, quart, gallon
  • Temperature: Fahrenheit (°F)

Conversions within the system aren't intuitive: 12 inches = 1 foot, 5,280 feet = 1 mile.

Length Conversions

Quick Reference

Metric Imperial Exact
1 mm 0.039 in
1 cm 0.394 in
1 m 3.281 ft
1 m 39.37 in
1 km 0.621 mi
2.54 cm 1 in exact
30.48 cm 1 ft exact
1.609 km 1 mi

Formulas

// Length conversions
const inchesToCm = (inches) => inches * 2.54;
const cmToInches = (cm) => cm / 2.54;

const feetToMeters = (feet) => feet * 0.3048;
const metersToFeet = (meters) => meters / 0.3048;

const milesToKm = (miles) => miles * 1.609344;
const kmToMiles = (km) => km / 1.609344;

Common Values

Imperial Metric
1 inch 2.54 cm
1 foot 30.48 cm
1 yard 0.914 m
1 mile 1.609 km
6 feet 1.83 m
100 yards 91.4 m
5K race 3.1 miles
Marathon 26.2 miles (42.2 km)

Weight/Mass Conversions

Quick Reference

Metric Imperial
1 g 0.035 oz
28.35 g 1 oz
1 kg 2.205 lb
453.6 g 1 lb

Formulas

// Weight conversions
const poundsToKg = (lb) => lb * 0.45359237;
const kgToPounds = (kg) => kg / 0.45359237;

const ouncesToGrams = (oz) => oz * 28.349523;
const gramsToOunces = (g) => g / 28.349523;

Common Values

Imperial Metric
1 ounce 28.35 g
1 pound 453.6 g
100 lb 45.4 kg
150 lb 68 kg
200 lb 90.7 kg

Volume Conversions

Quick Reference (US)

Metric US
1 mL 0.034 fl oz
29.57 mL 1 fl oz
1 L 0.264 gal
3.785 L 1 gal

Note: UK imperial volumes differ from US customary!

US vs UK Volumes

Unit US UK
Fluid ounce 29.57 mL 28.41 mL
Pint 473 mL 568 mL
Gallon 3.785 L 4.546 L

Formulas

// Volume conversions (US)
const litersToGallons = (L) => L * 0.264172;
const gallonsToLiters = (gal) => gal * 3.78541;

const mlToFlOz = (ml) => ml * 0.033814;
const flOzToMl = (floz) => floz * 29.5735;

Common Values

US Metric
1 cup 237 mL
1 pint 473 mL
1 quart 946 mL
1 gallon 3.79 L
12 fl oz (can) 355 mL
2 liter bottle 67.6 fl oz

Temperature Conversions

Formulas

// Temperature conversions
const celsiusToFahrenheit = (c) => (c * 9/5) + 32;
const fahrenheitToCelsius = (f) => (f - 32) * 5/9;

const celsiusToKelvin = (c) => c + 273.15;
const kelvinToCelsius = (k) => k - 273.15;

Reference Points

Description °F °C
Absolute zero -459.67 -273.15
Water freezes 32 0
Room temperature 68-72 20-22
Body temperature 98.6 37
Water boils 212 100

Quick Mental Math

For rough Celsius to Fahrenheit:

Double it and add 30

20°C → (20 × 2) + 30 = 70°F (actual: 68°F)
30°C → (30 × 2) + 30 = 90°F (actual: 86°F)

For rough Fahrenheit to Celsius:

Subtract 30 and halve it

70°F → (70 - 30) / 2 = 20°C (actual: 21°C)
90°F → (90 - 30) / 2 = 30°C (actual: 32°C)

Speed Conversions

Quick Reference

Metric Imperial
1 km/h 0.621 mph
1.609 km/h 1 mph
1 m/s 2.237 mph

Formulas

const kphToMph = (kph) => kph * 0.621371;
const mphToKph = (mph) => mph * 1.60934;

const msToMph = (ms) => ms * 2.23694;
const mphToMs = (mph) => mph / 2.23694;

Common Speeds

mph km/h
30 48
60 97
65 105
70 113
100 161

Area Conversions

Quick Reference

Metric Imperial
1 m² 10.76 ft²
1 hectare 2.47 acres
1 km² 0.386 mi²
1 ft² 0.093 m²
1 acre 4,047 m²

Formulas

const sqMetersToSqFeet = (m2) => m2 * 10.7639;
const sqFeetToSqMeters = (ft2) => ft2 / 10.7639;

const hectaresToAcres = (ha) => ha * 2.47105;
const acresToHectares = (acres) => acres / 2.47105;

Complete Conversion Library

Here's a reusable JavaScript conversion library:

const conversions = {
    length: {
        mmToIn: (mm) => mm * 0.0393701,
        inToMm: (inch) => inch * 25.4,
        cmToIn: (cm) => cm * 0.393701,
        inToCm: (inch) => inch * 2.54,
        mToFt: (m) => m * 3.28084,
        ftToM: (ft) => ft * 0.3048,
        kmToMi: (km) => km * 0.621371,
        miToKm: (mi) => mi * 1.60934
    },
    
    weight: {
        gToOz: (g) => g * 0.035274,
        ozToG: (oz) => oz * 28.3495,
        kgToLb: (kg) => kg * 2.20462,
        lbToKg: (lb) => lb * 0.453592
    },
    
    volume: {
        mlToFlOz: (ml) => ml * 0.033814,
        flOzToMl: (floz) => floz * 29.5735,
        lToGal: (l) => l * 0.264172,
        galToL: (gal) => gal * 3.78541
    },
    
    temperature: {
        cToF: (c) => (c * 9/5) + 32,
        fToC: (f) => (f - 32) * 5/9,
        cToK: (c) => c + 273.15,
        kToC: (k) => k - 273.15
    },
    
    speed: {
        kphToMph: (kph) => kph * 0.621371,
        mphToKph: (mph) => mph * 1.60934
    }
};

Python Equivalent

class Converter:
    # Length
    @staticmethod
    def cm_to_inches(cm): return cm / 2.54
    
    @staticmethod
    def inches_to_cm(inches): return inches * 2.54
    
    @staticmethod
    def km_to_miles(km): return km * 0.621371
    
    @staticmethod
    def miles_to_km(miles): return miles * 1.60934
    
    # Weight
    @staticmethod
    def kg_to_pounds(kg): return kg * 2.20462
    
    @staticmethod
    def pounds_to_kg(lb): return lb * 0.453592
    
    # Temperature
    @staticmethod
    def celsius_to_fahrenheit(c): return (c * 9/5) + 32
    
    @staticmethod
    def fahrenheit_to_celsius(f): return (f - 32) * 5/9

Tips for International Development

  1. Store in metric internally: Convert for display only
  2. Use locale settings: Detect user's preferred units
  3. Always show units: Never assume the user knows which system you're using
  4. Provide both: When possible, show both systems
  5. Be precise where it matters: Medical and scientific applications need accuracy

Summary

Converting Multiply by
inches → cm 2.54
cm → inches 0.3937
miles → km 1.609
km → miles 0.621
pounds → kg 0.454
kg → pounds 2.205
gallons (US) → liters 3.785
liters → gallons (US) 0.264
°F → °C (°F - 32) × 5/9
°C → °F (°C × 9/5) + 32

Need to convert units quickly? Try our Unit Converter!

Related Topics
metric imperial conversion units measurement length weight temperature
Share this article

Continue Reading

Converters
Temperature Scales: Celsius, Fahrenheit, and Kelvin

Understanding the three main temperature scales, their origins, how to convert between them, and when to use each one.

Calculators
Understanding BMI: What the Numbers Mean

A practical guide to Body Mass Index, how it's calculated, its limitations, and what the categories actually mean for health.

Converters
Understanding Foreign Exchange Rates: A Practical Guide

How currency exchange rates work: spot rates vs transfer rates, what affects exchange rates, hidden fees to watch for, and getting the best rate when sending money abroad.