Conversions Fuel Economy (2024 Guide) | CalcDomain
Detailed reference converted from the original conversions-fuel-economy.html page.
Loan Details
Taxes, Insurance & Fees (Optional)
Advanced Settings (Currency & Frequency)
Total Payment (Monthly Equivalent)
$0.00
Principal & Interest
$0.00
Taxes, Ins, HOA
$0.00
Total Interest Cost
$0.00
Payoff
—
| # | Total Payment | Interest | Principal | Extra | Balance |
|---|
Displaying first 360 rows. Download CSV for full data.
How to use
Enter the loan amount, interest rate, and term. Optionally add extra principal and escrow-related costs (taxes, insurance, PMI, HOA). Results update automatically with the Calculate button or inline edits.
Methodology
The calculator uses a fixed-rate amortization model, adding extra principal per period and rolling escrow costs into a monthly-equivalent total payment.
- “Monthly equivalent” keeps different payment frequencies comparable.
- Escrow components convert to a monthly cadence before addition.
- Payoff is shown as number of payments and a rough duration estimate.
Full original guide (expanded)
<script
async
src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-9476637732224939"
crossorigin="anonymous"
></script>
<header class="bg-white shadow-sm sticky top-0 z-50">
<nav class="container mx-auto px-4 lg:px-6 py-4" aria-label="Primary">
<div class="flex justify-between items-center">
<a
href="https://calcdomain.com"
class="text-2xl font-bold text-blue-600"
>CalcDomain</a
>
<div class="w-full max-w-md hidden md:block mx-8">
<div class="relative">
<input
type="search"
id="search-input"
placeholder="Search for a calculator..."
class="w-full py-2 px-4 pr-10 border border-gray-300 rounded-full focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"
autocomplete="off"
/>
<svg
class="w-5 h-5 absolute right-4 top-1/2 -translate-y-1/2 text-gray-400"
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"
></path>
</svg>
<div
id="search-results"
class="absolute top-full left-0 right-0 bg-white shadow-lg rounded-lg mt-2 max-h-96 overflow-y-auto z-50 hidden border border-gray-200"
></div>
</div>
</div>
<div class="hidden md:flex items-center space-x-6">
<a
href="https://calcdomain.com/search"
class="text-gray-700 hover:text-blue-600 transition-colors"
>Advanced Search</a
>
<a
href="https://calcdomain.com/#categories"
class="text-gray-700 hover:text-blue-600 transition-colors"
>Categories</a
>
</div>
<button
id="mobile-menu-toggle"
class="md:hidden p-2"
aria-controls="mobile-menu"
aria-expanded="false"
aria-label="Open menu"
type="button"
>
<svg
class="w-6 h-6"
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
aria-hidden="true"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M4 6h16M4 12h16M4 18h16"
></path>
</svg>
</button>
</div>
<nav
id="mobile-menu"
class="md:hidden mt-4 hidden"
aria-label="Mobile menu"
role="navigation"
>
<div class="mb-4">
<div class="relative">
<input
type="search"
id="mobile-search-input"
placeholder="Search calculators..."
class="w-full py-3 px-4 pr-10 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"
/>
<svg
class="w-5 h-5 absolute right-4 top-1/2 -translate-y-1/2 text-gray-400"
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
aria-hidden="true"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"
></path>
</svg>
</div>
</div>
<div class="space-y-2">
<a
href="https://calcdomain.com/search"
class="block py-2 text-gray-700 hover:text-blue-600"
>Advanced Search</a
>
<a
href="https://calcdomain.com/#categories"
class="block py-2 text-gray-700 hover:text-blue-600"
>Categories</a
>
</div>
</nav>
</nav>
</header>
<div class="container mx-auto px-4 py-8">
<nav id="breadcrumb-container" class="text-sm mb-4 text-gray-600">
<ol class="flex flex-wrap items-center gap-1">
<li><a href="https://calcdomain.com" class="text-blue-600 hover:underline">Home</a></li>
<li class="text-gray-400">/</li>
<li><a href="https://calcdomain.com/categories/math" class="text-blue-600 hover:underline">Math Calculators</a></li>
<li class="text-gray-400">/</li>
<li><a href="https://calcdomain.com/subcategories/math-conversions-measurement-unit-conversions" class="text-blue-600 hover:underline">Measurement Unit Conversions: Tools &</a></li>
<li class="text-gray-400">/</li>
<li><span class="text-gray-800">Fuel Economy Converter (MPG, L/100km, km/L, mi/L)</span></li>
</ol>
</nav>
<div class="flex flex-col lg:flex-row gap-8">
<main class="w-full lg:w-2/3">
<div class="bg-white p-6 rounded-lg shadow-md">
<header class="mb-6">
<h1 class="text-2xl font-bold mb-2">
Fuel Economy Converter (MPG, L/100km, km/L, mi/L)
</h1>
<p class="text-gray-700">
Convert fuel economy between MPG (US & UK), L/100km, km/L,
and mi/L. Enter a value in any unit and see all others update
instantly.
</p>
</header>
<section aria-labelledby="converter-heading" class="mb-8">
<h2 id="converter-heading" class="text-xl font-semibold mb-4">
Fuel economy conversions
</h2>
<div class="grid md:grid-cols-2 gap-4 mb-4">
<div>
<label
for="fe-mpg-us"
class="block text-sm font-medium text-gray-700 mb-1"
>
Miles per gallon (US)
<span class="ml-1 text-xs text-gray-500">(mpg US)</span>
</label>
<input
id="fe-mpg-us"
type="number"
step="0.0001"
inputmode="decimal"
class="w-full border border-gray-300 rounded-md px-3 py-2 focus:ring-2 focus:ring-blue-500 focus:border-transparent"
placeholder="e.g. 30"
/>
</div>
<div>
<label
for="fe-mpg-uk"
class="block text-sm font-medium text-gray-700 mb-1"
>
Miles per gallon (UK / Imperial)
<span class="ml-1 text-xs text-gray-500">(mpg UK)</span>
</label>
<input
id="fe-mpg-uk"
type="number"
step="0.0001"
inputmode="decimal"
class="w-full border border-gray-300 rounded-md px-3 py-2 focus:ring-2 focus:ring-blue-500 focus:border-transparent"
placeholder="e.g. 40"
/>
</div>
<div>
<label
for="fe-l-per-100km"
class="block text-sm font-medium text-gray-700 mb-1"
>
Liters per 100 kilometers
<span class="ml-1 text-xs text-gray-500">(L/100km)</span>
</label>
<input
id="fe-l-per-100km"
type="number"
step="0.0001"
inputmode="decimal"
class="w-full border border-gray-300 rounded-md px-3 py-2 focus:ring-2 focus:ring-blue-500 focus:border-transparent"
placeholder="e.g. 7.5"
/>
</div>
<div>
<label
for="fe-km-per-l"
class="block text-sm font-medium text-gray-700 mb-1"
>
Kilometers per liter
<span class="ml-1 text-xs text-gray-500">(km/L)</span>
</label>
<input
id="fe-km-per-l"
type="number"
step="0.0001"
inputmode="decimal"
class="w-full border border-gray-300 rounded-md px-3 py-2 focus:ring-2 focus:ring-blue-500 focus:border-transparent"
placeholder="e.g. 15"
/>
</div>
<div>
<label
for="fe-mi-per-l"
class="block text-sm font-medium text-gray-700 mb-1"
>
Miles per liter
<span class="ml-1 text-xs text-gray-500">(mi/L)</span>
</label>
<input
id="fe-mi-per-l"
type="number"
step="0.0001"
inputmode="decimal"
class="w-full border border-gray-300 rounded-md px-3 py-2 focus:ring-2 focus:ring-blue-500 focus:border-transparent"
placeholder="e.g. 25"
/>
</div>
</div>
<div
class="flex flex-col md:flex-row md:items-center md:justify-between gap-3 mt-2"
>
<div class="flex items-center gap-2">
<label
for="fe-precision"
class="text-sm text-gray-700 font-medium"
>Decimal places:</label
>
<select
id="fe-precision"
class="border border-gray-300 rounded-md px-2 py-1 text-sm focus:ring-2 focus:ring-blue-500 focus:border-transparent"
>
<option value="1">1</option>
<option value="2" selected>2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
</div>
<button
id="fe-reset"
type="button"
class="inline-flex items-center justify-center px-3 py-2 border border-gray-300 rounded-md text-sm font-medium text-gray-700 hover:bg-gray-100"
>
Clear all
</button>
</div>
</section>
<section aria-labelledby="quick-comparison-heading" class="mb-8">
<h2
id="quick-comparison-heading"
class="text-xl font-semibold mb-3"
>
Quick comparison table
</h2>
<p class="text-sm text-gray-700 mb-2">
See how common fuel economy values compare across units.
</p>
<div class="overflow-x-auto border border-gray-200 rounded-md">
<table class="min-w-full text-sm">
<thead class="bg-gray-100">
<tr>
<th
class="px-3 py-2 text-left font-semibold text-gray-700"
>
L/100km
</th>
<th
class="px-3 py-2 text-left font-semibold text-gray-700"
>
MPG (US)
</th>
<th
class="px-3 py-2 text-left font-semibold text-gray-700"
>
MPG (UK)
</th>
<th
class="px-3 py-2 text-left font-semibold text-gray-700"
>
km/L
</th>
</tr>
</thead>
<tbody
id="fe-sample-table-body"
class="divide-y divide-gray-100"
>
<!-- Filled by JS -->
</tbody>
</table>
</div>
</section>
<section class="prose">
<h2>How this fuel economy converter works</h2>
<p>
This tool converts between the most common fuel economy and fuel
consumption units used worldwide:
</p>
<ul>
<li>
<strong>MPG (US)</strong> – miles per US gallon (3.785 L)
</li>
<li>
<strong>MPG (UK)</strong> – miles per Imperial gallon
(4.546 L)
</li>
<li><strong>L/100km</strong> – liters per 100 kilometers</li>
<li><strong>km/L</strong> – kilometers per liter</li>
<li><strong>mi/L</strong> – miles per liter</li>
</ul>
<p>
Enter a value in <em>any</em> field and the calculator will
instantly update all the others using precise conversion
factors. You can also adjust the number of decimal places to
match your needs.
</p>
<h2>Conversion formulas</h2>
<p>
Internally, the converter uses exact relationships between
distance and volume units.
</p>
<div class="formula-box text-sm">
<p class="font-semibold mb-1">Base constants</p>
<ul class="list-disc pl-5">
<li>1 mile = 1.609344 km</li>
<li>1 US gallon = 3.785411784 L</li>
<li>1 UK (Imperial) gallon = 4.54609 L</li>
</ul>
</div>
<h3>From L/100km to MPG and km/L</h3>
<p>
L/100km is a <em>consumption</em> unit (fuel per distance). MPG
and km/L are <em>economy</em> units (distance per fuel). That’s
why the formulas use a reciprocal.
</p>
<div class="formula-box text-sm">
<p>Let \( C \) be fuel consumption in L/100km.</p>
<p class="mt-2">
US MPG: \[ \text{MPG}_{US} = \frac{235.214583}{C} \]
</p>
<p>UK MPG: \[ \text{MPG}_{UK} = \frac{282.480936}{C} \]</p>
<p>km/L: \[ \text{km/L} = \frac{100}{C} \]</p>
<p>mi/L: \[ \text{mi/L} = \frac{62.137119}{C} \]</p>
</div>
<h3>From MPG to L/100km</h3>
<div class="formula-box text-sm">
<p>Let \( E_{US} \) be US MPG and \( E_{UK} \) be UK MPG.</p>
<p class="mt-2">
From US MPG: \[ C = \frac{235.214583}{E_{US}} \]
</p>
<p>From UK MPG: \[ C = \frac{282.480936}{E_{UK}} \]</p>
</div>
<h3>From km/L and mi/L</h3>
<div class="formula-box text-sm">
<p>Let \( K \) be km/L and \( M \) be mi/L.</p>
<p class="mt-2">L/100km from km/L: \[ C = \frac{100}{K} \]</p>
<p>L/100km from mi/L: \[ C = \frac{62.137119}{M} \]</p>
<p>
US MPG from km/L: \[ \text{MPG}_{US} = K \cdot
\frac{100}{3.785411784} \]
</p>
<p>
UK MPG from km/L: \[ \text{MPG}_{UK} = K \cdot
\frac{100}{4.54609} \]
</p>
</div>
<h2>Typical fuel economy values</h2>
<p>
Very roughly, you can think of these ranges for passenger cars:
</p>
<ul>
<li>
<strong>10–12 L/100km</strong> (≈ 19–24 US MPG) – older or
large SUVs, city driving
</li>
<li>
<strong>7–8 L/100km</strong> (≈ 29–34 US MPG) – average modern
compact car
</li>
<li>
<strong>5–6 L/100km</strong> (≈ 39–47 US MPG) – efficient
diesel or hybrid
</li>
<li>
<strong>< 4 L/100km</strong> (≈ > 59 US MPG) – very
efficient hybrids or plug‑in hybrids
</li>
</ul>
<h2>Fuel economy vs. fuel consumption</h2>
<p>
It’s easy to get confused because some countries report how far
you can drive on a unit of fuel, while others report how much
fuel you need to drive a fixed distance:
</p>
<ul>
<li>
<strong>Economy (higher is better)</strong>: MPG, km/L, mi/L
</li>
<li>
<strong>Consumption (lower is better)</strong>: L/100km,
gal/100mi
</li>
</ul>
<p>
When comparing cars across regions (for example, US MPG vs
European L/100km), always convert to the same type of measure
first.
</p>
</section>
</div>
<section class="mt-10" id="author">
<h2 class="text-xl font-semibold mb-4">About the author</h2>
<div class="bg-gray-50 border border-gray-200 rounded-lg p-4">
<p class="text-sm text-gray-700">
<a href="https://www.linkedin.com/in/ugocandido92821/" class="text-blue-600 hover:underline" target="_blank" rel="noopener">Ugo Candido</a>
builds financial tools and educational resources to help
readers make better money decisions. He focuses on practical,
transparent models that reflect how lenders calculate
payments and total cost of ownership.
</p>
<p class="text-sm text-gray-700 mt-3">
Contact: <a href="mailto:info@calcdomain.com" class="text-blue-600 hover:underline">info@calcdomain.com</a>
</p>
</div>
</section>
<section class="mt-10" id="editorial-policy">
<h2 class="text-xl font-semibold mb-4">Editorial policy</h2>
<div class="bg-gray-50 border border-gray-200 rounded-lg p-4">
<p class="text-sm text-gray-700">
CalcDomain content is created for educational purposes and is
reviewed for clarity, accuracy, and transparency. We do not
accept paid placements that influence calculator outputs.
Inputs and assumptions are shown directly in the interface so
you can verify how results are produced.
</p>
</div>
</section>
<section class="mt-10" id="methodology">
<h2 class="text-xl font-semibold mb-4">Methodology</h2>
<div class="bg-gray-50 border border-gray-200 rounded-lg p-4">
<p class="text-sm text-gray-700">
Results use standard formulas and the values you provide.
Figures are estimates and may differ from lender quotes.
For decisions that require professional guidance, consult a
licensed advisor.
</p>
</div>
</section>
<section class="mt-10" id="sources">
<h2 class="text-xl font-semibold mb-4">Sources</h2>
<div class="bg-gray-50 border border-gray-200 rounded-lg p-4">
<ul class="list-disc list-inside text-sm text-gray-700 space-y-1">
<li>
<a href="https://www.nist.gov/pml/owm/metric-si/si-units" class="text-blue-600 hover:underline" target="_blank" rel="noopener">
NIST: The International System of Units (SI)
</a>
</li>
<li>
<a href="https://openstax.org/details/books/college-algebra" class="text-blue-600 hover:underline" target="_blank" rel="noopener">
OpenStax: College Algebra
</a>
</li>
</ul>
</div>
</section>
<section class="bg-white p-4 rounded-lg shadow-md mt-6"><h2 class="text-lg font-semibold mb-2">Operational notes</h2><p class="text-sm text-gray-700">Fill in realistic values and keep units and timeframes consistent.</p><p class="text-sm text-gray-700 mt-2">Key entities: Conversions, Fuel, Economy, Miles per gallon (US) (mpg US), Miles per gallon (UK / Imperial) (mpg UK), Liters per 100 kilometers (L/100km), Kilometers per liter (km/L), Miles per liter (mi/L).</p></section><section class="bg-white p-4 rounded-lg shadow-md mt-6"><h2 class="text-lg font-semibold mb-2">Inputs used by this calculator</h2><ul class="text-sm text-gray-700 list-disc pl-5"><li>Miles per gallon (US) (mpg US)</li><li>Miles per gallon (UK / Imperial) (mpg UK)</li><li>Liters per 100 kilometers (L/100km)</li><li>Kilometers per liter (km/L)</li><li>Miles per liter (mi/L)</li></ul></section><section class="bg-white p-4 rounded-lg shadow-md mt-6"><h2 class="text-lg font-semibold mb-2">Consistency checks</h2><p class="text-sm text-gray-700">Checks: non-negative values, plausible ranges, coherent outputs.</p></section><!-- %%EEAT_STRIP%% -->
<!-- %%QUALITY_BLOCKS%% -->
<!-- %%FAQ_JSONLD%% -->
</main>
<aside class="w-full lg:w-1/3">
<div class="bg-white p-4 rounded-lg shadow-md mb-6">
<h2 class="text-lg font-semibold mb-3">Related unit converters</h2>
<ul class="space-y-2 text-sm">
<li>
<a
href="https://calcdomain.com/speed-converter"
class="text-blue-600 hover:underline"
>
Speed Unit Converter (mph, kph, m/s, knots)
</a>
</li>
<li>
<a
href="https://calcdomain.com/length-converter"
class="text-blue-600 hover:underline"
>
Length Unit Converter (miles, km, feet, meters)
</a>
</li>
<li>
<a
href="https://calcdomain.com/energy-unit-converter"
class="text-blue-600 hover:underline"
>
Energy Unit Converter (joules, calories, kWh, BTU)
</a>
</li>
<li>
<a
href="https://calcdomain.com/volume-converter"
class="text-blue-600 hover:underline"
>
Volume Unit Converter (Gallons, Liters, cubic ft, cubic m)
</a>
</li>
<li>
<a
href="https://calcdomain.com/weight-converter"
class="text-blue-600 hover:underline"
>
Weight/Mass Unit Converter (lbs, kg, stone, tons)
</a>
</li>
<li>
<a
href="https://calcdomain.com/steps-to-miles"
class="text-blue-600 hover:underline"
>
Steps to Miles
</a>
</li>
<li>
<a
href="https://calcdomain.com/conversions-speed"
class="text-blue-600 hover:underline"
>
Speed Conversions
</a>
</li>
<li>
<a
href="https://calcdomain.com/conversions-volume-and-capacity"
class="text-blue-600 hover:underline"
>
Volume & Capacity Conversions
</a>
</li>
</ul>
</div>
<div class="bg-white p-4 rounded-lg shadow-md">
<h2 class="text-lg font-semibold mb-3">
Measurement Unit Conversions
</h2>
<ul class="space-y-2 text-sm">
<li>
<a
href="https://calcdomain.com/area-converter"
class="text-blue-600 hover:underline"
>Area Unit Converter</a
>
</li>
<li>
<a
href="https://calcdomain.com/pressure-unit-converter"
class="text-blue-600 hover:underline"
>Pressure Unit Converter</a
>
</li>
<li>
<a
href="https://calcdomain.com/data-storage-converter"
class="text-blue-600 hover:underline"
>Data Storage Converter</a
>
</li>
<li>
<a
href="https://calcdomain.com/angle-converter"
class="text-blue-600 hover:underline"
>Angle Unit Converter</a
>
</li>
<li>
<a
href="https://calcdomain.com/unit-converter"
class="text-blue-600 hover:underline"
>Universal Unit Converter</a
>
</li>
</ul>
</div>
</aside>
</div>
</div>
<footer class="bg-gray-900 text-white py-12">
<div class="container mx-auto px-4">
<div class="grid grid-cols-1 md:grid-cols-4 gap-8">
<div>
<h3 class="text-2xl font-bold mb-4">CalcDomain</h3>
<p class="text-gray-400 mb-4">
Your trusted source for free online calculators. Accurate, fast,
and reliable calculations for every need.
</p>
</div>
<div>
<h4 class="text-lg font-semibold mb-4">Categories</h4>
<ul class="space-y-2">
<li>
<a
href="https://calcdomain.com/finance"
class="text-gray-400 hover:text-white"
>Finance</a
>
</li>
<li>
<a
href="https://calcdomain.com/health-fitness"
class="text-gray-400 hover:text-white"
>Health & Fitness</a
>
</li>
<li>
<a
href="https://calcdomain.com/math-conversions"
class="text-gray-400 hover:text-white"
>Math & Conversions</a
>
</li>
<li>
<a
href="https://calcdomain.com/lifestyle-everyday"
class="text-gray-400 hover:text-white"
>Lifestyle & Everyday</a
>
</li>
<li>
<a
href="https://calcdomain.com/construction-diy"
class="text-gray-400 hover:text-white"
>Construction & DIY</a
>
</li>
</ul>
</div>
<div>
<h4 class="text-lg font-semibold mb-4">Popular Tools</h4>
<ul class="space-y-2">
<li>
<a
href="https://calcdomain.com/mortgage-payment"
class="text-gray-400 hover:text-white"
>Mortgage Calculator</a
>
</li>
<li>
<a
href="https://calcdomain.com/percentage-calculator"
class="text-gray-400 hover:text-white"
>Percentage Calculator</a
>
</li>
<li>
<a
href="https://calcdomain.com/bmi-calculator"
class="text-gray-400 hover:text-white"
>BMI Calculator</a
>
</li>
<li>
<a
href="https://calcdomain.com/auto-loan-calculator"
class="text-gray-400 hover:text-white"
>Auto Loan Calculator</a
>
</li>
<li>
<a
href="https://calcdomain.com/house-affordability"
class="text-gray-400 hover:text-white"
>House Affordability</a
>
</li>
</ul>
</div>
<div>
<h4 class="text-lg font-semibold mb-4">Support</h4>
<ul class="space-y-2">
<li>
<a
href="https://calcdomain.com/about"
class="text-gray-400 hover:text-white"
>About Us</a
>
</li>
<li>
<a
href="https://calcdomain.com/contact"
class="text-gray-400 hover:text-white"
>Contact</a
>
</li>
<li>
<a
href="https://calcdomain.com/privacy"
class="text-gray-400 hover:text-white"
>Privacy Policy</a
>
</li>
<li>
<a
href="https://calcdomain.com/terms"
class="text-gray-400 hover:text-white"
>Terms of Service</a
>
</li>
<li>
<a
href="https://calcdomain.com/sitemap.xml"
class="text-gray-400 hover:text-white"
>Site Map</a
>
</li>
</ul>
</div>
</div>
<div
class="border-t border-gray-800 mt-8 pt-8 text-center text-gray-400"
>
<p>
© 2025 CalcDomain. All Rights Reserved. | Free Online
Calculators for Everyone
</p>
</div>
</div>
</footer>
<script src="/assets/js/mobile-menu.js"></script>
<script src="/search.js"></script>
<script>
(function () {
const MPG_US_PER_MPG_UK = 0.83267418463; // 1 UK MPG ≈ 1.20095 US MPG -> inverse
const KM_PER_MILE = 1.609344;
const L_PER_US_GAL = 3.785411784;
const L_PER_UK_GAL = 4.54609;
const inputs = {
mpgUs: document.getElementById("fe-mpg-us"),
mpgUk: document.getElementById("fe-mpg-uk"),
lPer100: document.getElementById("fe-l-per-100km"),
kmPerL: document.getElementById("fe-km-per-l"),
miPerL: document.getElementById("fe-mi-per-l"),
};
const precisionSelect = document.getElementById("fe-precision");
const resetBtn = document.getElementById("fe-reset");
const sampleBody = document.getElementById("fe-sample-table-body");
let updating = false;
function getPrecision() {
const p = parseInt(precisionSelect.value, 10);
return isNaN(p) ? 2 : p;
}
function round(value) {
if (!isFinite(value)) return "";
const p = getPrecision();
return Number(value.toFixed(p));
}
function fromLPer100(C) {
const kmPerL = 100 / C;
const miPerL = (100 * KM_PER_MILE) / (100 * C); // simplifies to KM_PER_MILE / C
const mpgUs = (100 * KM_PER_MILE) / (C * L_PER_US_GAL);
const mpgUk = (100 * KM_PER_MILE) / (C * L_PER_UK_GAL);
return { kmPerL, miPerL, mpgUs, mpgUk };
}
function updateFromLPer100(value) {
const C = parseFloat(value);
if (!isFinite(C) || C <= 0) {
clearAllExcept("lPer100");
return;
}
const res = fromLPer100(C);
inputs.kmPerL.value = round(res.kmPerL);
inputs.miPerL.value = round(res.miPerL);
inputs.mpgUs.value = round(res.mpgUs);
inputs.mpgUk.value = round(res.mpgUk);
}
function updateFromMpgUs(value) {
const mpgUs = parseFloat(value);
if (!isFinite(mpgUs) || mpgUs <= 0) {
clearAllExcept("mpgUs");
return;
}
const C = 235.214583 / mpgUs;
inputs.lPer100.value = round(C);
updateFromLPer100(C);
}
function updateFromMpgUk(value) {
const mpgUk = parseFloat(value);
if (!isFinite(mpgUk) || mpgUk <= 0) {
clearAllExcept("mpgUk");
return;
}
const C = 282.480936 / mpgUk;
inputs.lPer100.value = round(C);
updateFromLPer100(C);
}
function updateFromKmPerL(value) {
const kmPerL = parseFloat(value);
if (!isFinite(kmPerL) || kmPerL <= 0) {
clearAllExcept("kmPerL");
return;
}
const C = 100 / kmPerL;
inputs.lPer100.value = round(C);
updateFromLPer100(C);
}
function updateFromMiPerL(value) {
const miPerL = parseFloat(value);
if (!isFinite(miPerL) || miPerL <= 0) {
clearAllExcept("miPerL");
return;
}
const C = (KM_PER_MILE * 100) / (miPerL * 100); // simplifies to KM_PER_MILE / miPerL
const Cexact = KM_PER_MILE / miPerL;
inputs.lPer100.value = round(Cexact);
updateFromLPer100(Cexact);
}
function clearAllExcept(key) {
Object.keys(inputs).forEach((k) => {
if (k !== key) inputs[k].value = "";
});
}
function attachListeners() {
inputs.lPer100.addEventListener("input", () => {
if (updating) return;
updating = true;
updateFromLPer100(inputs.lPer100.value);
updating = false;
});
inputs.mpgUs.addEventListener("input", () => {
if (updating) return;
updating = true;
updateFromMpgUs(inputs.mpgUs.value);
updating = false;
});
inputs.mpgUk.addEventListener("input", () => {
if (updating) return;
updating = true;
updateFromMpgUk(inputs.mpgUk.value);
updating = false;
});
inputs.kmPerL.addEventListener("input", () => {
if (updating) return;
updating = true;
updateFromKmPerL(inputs.kmPerL.value);
updating = false;
});
inputs.miPerL.addEventListener("input", () => {
if (updating) return;
updating = true;
updateFromMiPerL(inputs.miPerL.value);
updating = false;
});
precisionSelect.addEventListener("change", () => {
// Re-run last non-empty field to re-round values
const order = ["lPer100", "mpgUs", "mpgUk", "kmPerL", "miPerL"];
for (const key of order) {
const el = inputs[key];
if (el.value !== "") {
updating = true;
switch (key) {
case "lPer100":
updateFromLPer100(el.value);
break;
case "mpgUs":
updateFromMpgUs(el.value);
break;
case "mpgUk":
updateFromMpgUk(el.value);
break;
case "kmPerL":
updateFromKmPerL(el.value);
break;
case "miPerL":
updateFromMiPerL(el.value);
break;
}
updating = false;
break;
}
}
});
resetBtn.addEventListener("click", () => {
Object.values(inputs).forEach((el) => (el.value = ""));
});
}
function buildSampleTable() {
const sampleL = [4, 5, 6, 7, 8, 10, 12];
const rows = sampleL
.map((C) => {
const res = fromLPer100(C);
const mpgUs = (100 * KM_PER_MILE) / (C * L_PER_US_GAL);
const mpgUk = (100 * KM_PER_MILE) / (C * L_PER_UK_GAL);
return `
<tr>
<td class="px-3 py-1.5">${C.toFixed(1)}</td>
<td class="px-3 py-1.5">${mpgUs.toFixed(1)}</td>
<td class="px-3 py-1.5">${mpgUk.toFixed(1)}</td>
<td class="px-3 py-1.5">${res.kmPerL.toFixed(2)}</td>
</tr>
`;
})
.join("");
sampleBody.innerHTML = rows;
}
attachListeners();
buildSampleTable();
})();
</script>
<script>
window.MathJax = {
tex: {
inlineMath: [
["\\(", "\\)"],
["$", "$"],
],
displayMath: [
["$", "$"],
["\\[", "\\]"],
],
},
svg: { fontCache: "global" },
};
</script>
<script>
(function () {
var loadMathJax = function () {
if (window.__mathjaxLoading) return;
window.__mathjaxLoading = true;
var script = document.createElement("script");
script.id = "MathJax-script";
script.async = true;
script.src = "https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js";
document.head.appendChild(script);
};
var target = document.querySelector(
".formula-box, .mathjax, .math, .formula, [data-mathjax]"
);
if (!target) return;
if ("IntersectionObserver" in window) {
var observer = new IntersectionObserver(
function (entries) {
if (entries.some(function (entry) { return entry.isIntersecting; })) {
observer.disconnect();
loadMathJax();
}
},
{ rootMargin: "200px" }
);
observer.observe(target);
} else {
window.addEventListener(
"load",
function () {
setTimeout(loadMathJax, 1000);
},
{ once: true }
);
}
})();
</script>
<script async src="https://www.googletagmanager.com/gtag/js?id=G-7MB5V1LZRN"></script>
<script>
window.__cmpLoadQueued = window.__cmpLoadQueued || [];
window.addEventListener("load", function () {
var loadCmp = function () {
var s1 = document.createElement("script");
s1.src = "https://cmp.gatekeeperconsent.com/min.js";
s1.async = true;
s1.setAttribute("data-cfasync", "false");
document.head.appendChild(s1);
var s2 = document.createElement("script");
s2.src = "https://the.gatekeeperconsent.com/cmp.min.js";
s2.async = true;
s2.setAttribute("data-cfasync", "false");
document.head.appendChild(s2);
};
if ("requestIdleCallback" in window) {
requestIdleCallback(loadCmp, { timeout: 2000 });
} else {
setTimeout(loadCmp, 1000);
}
});
</script>
<script async src="//www.ezojs.com/ezoic/sa.min.js"></script>
<script>
window.ezstandalone = window.ezstandalone || {};
ezstandalone.cmd = ezstandalone.cmd || [];
</script>