Journey cost calculator UK: by number plate and postcode
Work out what a car journey will cost: type your number plate and two postcodes, or your own figures. Petrol, diesel or electric, one way or return, split between passengers.
Type your number plate and two postcodes, and the calculator finds your car’s real-world fuel economy and the distance by road, then shows what the trip will cost in petrol, diesel or electricity. You can also type the figures yourself. It works one way or return, splits the cost between passengers, and uses current UK prices: petrol at 175.3p and diesel at 200.0p a litre (UK averages for the week of 12 October 2026).
The calculator needs JavaScript switched on in your browser.
Every figure can be changed, so you can use the price on the pump at your local filling station or the rate on your own electricity bill. Press “Show the working” to see each step of the sum.
Find your car’s fuel economy from its number plate
Type your number plate and press “Find my car”. The calculator gets the make, model, engine size, fuel and year from the DVSA’s MOT history records, then looks up the official fuel economy of that model in the Vehicle Certification Agency’s lists of new cars, which go back to 2000. If several versions of your car match, it uses the middle figure and shows the range.
Official figures come from a laboratory test, and cars use more fuel on real roads. So the calculator fills in a real-world estimate instead:
- Cars tested on WLTP (most cars sold from 2019): petrol cars use about 24% more fuel than the official figure, and diesel cars about 18% more. These figures come from fuel meters in cars registered in 2021 (European Commission). The calculator uses the petrol figure for hybrids too.
- Older cars tested on NEDC: the gap grew over the years, from about 9% for cars from 2001 to about 40% for cars from 2015 to 2017 (International Council on Clean Transportation).
- Plug-in hybrids: on average 4 litres per 100 km more than the official figure (European Commission). Your own figure depends on how often you charge the battery.
- Electric cars: about 18% fewer miles per kWh than the official figure, because in Which?’s tests of 60 electric cars, they went about 18% less far on a charge than their official range.
Vans, cars from before 2000 and a few newer makes are not on the official lists, so for those you type the fuel economy yourself. If you know your own car’s figure from its trip computer or a fill-up (see below), type that in: it is better than any estimate.
Get the distance from two postcodes
Type the start and end postcodes and press “Get the miles”. The calculator finds both postcodes and works out the distance by road with OpenRouteService, which uses OpenStreetMap’s road map. It fills in the one-way distance; choose “Return” for the trip there and back. The first part of a postcode, such as LS1, also works. Northern Ireland postcodes are not covered, so type those distances yourself.
What happens to your number plate and postcodes. Braindumps sends them to the DVSA, postcodes.io and OpenRouteService only to do the lookup, and does not keep a list of them. So that repeat lookups are quick, the answer is kept for up to 30 days in a form that cannot be turned back into the number plate or postcodes.
What it costs to drive 100 miles in the UK
The table shows the fuel cost of 100 miles at this week’s average prices. It also gives you the cost per mile: divide by 100, so £17.71 for 100 miles is 17.7p a mile.
| Fuel economy | Petrol (175.3p a litre) | Diesel (200.0p a litre) |
|---|---|---|
| 30 mpg | £26.56 | £30.31 |
| 35 mpg | £22.77 | £25.98 |
| 40 mpg | £19.92 | £22.73 |
| 45 mpg | £17.71 | £20.20 |
| 50 mpg | £15.94 | £18.18 |
| 55 mpg | £14.49 | £16.53 |
| 60 mpg | £13.28 | £15.15 |
| 65 mpg | £12.26 | £13.99 |
| 70 mpg | £11.38 | £12.99 |
Diesel costs about 25p a litre more than petrol at the moment, so a diesel car needs to do roughly 14% more miles per gallon than a petrol car just to cost the same per mile.
For an electric car, the cost depends far more on where you charge than on the car:
| Efficiency | Home (26.32p a kWh) | Public slow or fast (54p) | Public rapid (79p) |
|---|---|---|---|
| 2.5 miles per kWh | £10.53 | £21.60 | £31.60 |
| 3.0 miles per kWh | £8.77 | £18.00 | £26.33 |
| 3.5 miles per kWh | £7.52 | £15.43 | £22.57 |
| 4.0 miles per kWh | £6.58 | £13.50 | £19.75 |
| 4.5 miles per kWh | £5.85 | £12.00 | £17.56 |
How to work out the fuel cost of a journey
You need three numbers: the distance, your car’s miles per gallon (mpg) and the price of fuel. UK pumps sell fuel by the litre but cars are rated in miles per gallon, so there is one conversion in the middle. A UK gallon is 4.546 litres.
- Divide the distance by your mpg to get the gallons used.
- Multiply the gallons by 4.546 to get litres.
- Multiply the litres by the price per litre.
Worked example. A 120-mile drive to see family, there and back, in a petrol car that does 48 mpg, with £8 of parking, shared by three people:
- Distance: 120 miles × 2 = 240 miles
- Gallons: 240 ÷ 48 = 5.0 gallons
- Litres: 5.0 × 4.546 = 22.73 litres
- Fuel: 22.73 × 175.3p = £39.85
- With parking: £39.85 + £8.00 = £47.85, or £15.95 each
The fuel works out at 16.6p a mile. Put the same figures into the calculator above and press “Show the working” to see the same steps.
Cost per mile: turning mpg into pence per mile
To compare cars, or to check a mileage claim, work out what one mile costs:
Pence per mile = 4.546 × price per litre ÷ mpg
At 175.3p a litre and 45 mpg, that is 4.546 × 175.3 ÷ 45 = 17.7p a mile. If your car shows litres per 100 km instead, the calculator converts it for you; 45 mpg is the same as 6.3 litres per 100 km.
How to find your car’s real fuel economy
The figure on your car’s trip computer is a good start, but it is often a little optimistic. For the real figure, measure it from one fill-up to the next:
- Fill the tank to the brim and reset the trip meter.
- Drive as normal until the tank is around half empty.
- Fill to the brim again and note how many litres it took.
- Divide the miles on the trip meter by the litres, then multiply by 4.546. That is your mpg.
Most cars use more fuel on short trips, in heavy traffic, at motorway speeds above 70 mph, with a roof box or a full boot, and in cold weather. Many family cars do 40 to 55 mpg on a mixed journey.
Electric cars: charging at home or on the road
At home on the standard price cap in England, Scotland and Wales, electricity costs 26.32p a kWh from 1 October to 31 December 2026, and there is no VAT on household electricity in Great Britain from 1 October 2026 to 31 March 2027. An electric car that does 3.5 miles per kWh therefore costs about 7.5p a mile to run on home electricity, under half the cost of a 45 mpg petrol car.
Public chargers cost far more. Zapmap’s price index puts the UK pay-as-you-go average at 54p a kWh for slow and fast chargers and 79p for rapid and ultra-rapid chargers (September 2026). On a long trip that needs rapid charging, an electric car can cost more per mile than a petrol car. Many drivers pay less than these averages by using an overnight electricity tariff at home or a charging network’s subscription (our EV charging subscription calculator shows whether one would pay for itself), so choose “My own price” in the calculator and enter your own rate.
Electric cars also cover fewer miles per kWh in winter, when the heater and the battery’s own warming use energy. In What Car?’s winter tests, cars fell 16% to 33% short of their official range, and three cars tested in both seasons covered 18% fewer miles in winter than in summer. Lower the miles per kWh in the calculator for a winter trip.
Sharing the cost of a lift
Set “People sharing the cost” to the number of people paying, and the calculator divides the total, including parking and tolls, equally. Whether the driver pays a share is up to you: some drivers count themselves in, and others ask passengers to cover the fuel only, because the driver also pays for insurance, wear and servicing. Agree it before you set off.
Claiming mileage for work
If you use your own car for work, HMRC’s approved mileage rate for 2026 to 2027 is 55p a mile for the first 10,000 business miles in the tax year and 25p a mile after that. The 55p rate is backdated to 6 April 2026; it was 45p before. Your employer can pay you up to these rates without tax, and if they pay less, you can claim tax relief on the difference.
The rate is meant to cover more than fuel, including wear and insurance. The calculator’s fuel cost per mile shows how much of it goes on fuel.
Company car drivers use HMRC’s advisory fuel rates instead. From 1 September 2026 they are:
| Engine size | Petrol | Diesel |
|---|---|---|
| Petrol 1,400cc or less; diesel 1,600cc or less | 14p a mile | 15p a mile |
| Petrol 1,401cc to 2,000cc; diesel 1,601cc to 2,000cc | 17p a mile | 16p a mile |
| Over 2,000cc | 27p a mile | 22p a mile |
For fully electric company cars, the advisory electricity rate is 7p a mile when charged at home and 15p a mile on public chargers.
The prices this calculator uses
- Petrol and diesel: 175.3p and 200.0p a litre, the UK average pump prices for the week of 12 October 2026 from the government’s weekly road fuel price statistics.
- Home electricity: 26.32p a kWh, Ofgem’s energy price cap for 1 October to 31 December 2026 (paying by Direct Debit, average for England, Scotland and Wales).
- Public charging: 54p a kWh (slow and fast) and 79p a kWh (rapid and ultra-rapid), Zapmap’s pay-as-you-go averages for September 2026.
Braindumps checks these prices every month and updates the calculator when they move.
Questions people ask
How much does it cost to drive 100 miles in the UK?
At current average prices, about £17.70 in a petrol car that does 45 mpg, £17.50 in a diesel car that does 52 mpg, and about £7.50 in an electric car charged at home. The tables above show other fuel economies.
Can I find my car’s mpg from its number plate?
Yes. Type it into the calculator above and press “Find my car”. You get the official figure for your model and a real-world estimate, which is lower, and the estimate is filled in for you.
How do I work out the fuel cost for a journey?
Divide the miles by your car’s mpg, multiply by 4.546 to get litres, then multiply by the price per litre. The calculator does this for you and shows each step.
Does driving faster use more fuel?
Yes. Air resistance rises with the square of your speed, so fuel use climbs quickly at motorway speeds. The Department for Transport says a car uses about 10% more fuel at 70 mph than at 60 mph, and about 25% more at 85 mph than at 70 mph.
Is this calculator accurate?
The sums are exact, but the answer is only as good as the fuel economy you enter. Traffic, hills, weather and load all change it, so treat the answer as a close estimate rather than an exact figure. Measuring your real mpg (see above) gives the best result.
Our other car tools use the same number plate lookup: the MOT history checker explains every MOT a car has had, advisory by advisory, and the electric car cost calculator works out what an electric car would cost you for the miles your car really does.
For the electricity cost of running other things, see the 3D print cost calculator, which uses the same price cap figures. More free calculators are in the Tools section.
Sources
GOV.UK: weekly road fuel prices; Ofgem: energy price cap, 1 October to 31 December 2026; Ofgem: price cap unit rates and VAT; Zapmap: UK EV charging price index; LITRG: increase to mileage rates for 2026 to 2027; CIPP: advisory fuel rates from 1 September 2026; GOV.UK: temporary zero rate of VAT on domestic electricity in Great Britain; Department for Transport: fuel use at higher speeds; Fleet News: What Car? winter range tests; DVSA: MOT history API; Vehicle Certification Agency: car fuel data; European Commission: real-world CO2 emissions from cars (2024); ICCT: From laboratory to road; Which?: the truth about electric car range; postcodes.io; OpenRouteService.
Vehicle details contain public sector information licensed under the Open Government Licence v3.0. Fuel economy data: Vehicle Certification Agency, Crown copyright. Postcodes: contains OS data © Crown copyright and database right 2025; contains Royal Mail data © Royal Mail copyright and database right 2025; contains National Statistics data © Crown copyright and database right 2025; contains NRS data © Crown copyright and database right 2025. Road distances: © openrouteservice.org by HeiGIT, map data © OpenStreetMap contributors.
Use this calculator on your own site
You are welcome to use this calculator on your own website. Copy the code below into a Custom HTML block in WordPress, or into any web page. It needs no other files. This version leaves out the number plate and postcode lookups, so it needs no API key or account: people type in the distance and their car’s fuel economy themselves. We only ask that you keep the link to Braindumps at the bottom.
<!-- Braindumps journey cost calculator (UK). Self-contained: no external files. Prices are UK averages; change them to your own. -->
<div id="bd-jcc">
<style>
#bd-jcc{--bd-red:#d63333;--bd-line:rgba(127,127,127,.35);--bd-soft:rgba(127,127,127,.08);font:inherit;color:inherit;max-width:760px;margin:1.5em 0}
#bd-jcc *{box-sizing:border-box}
#bd-jcc [hidden]{display:none!important}
#bd-jcc fieldset{border:1px solid var(--bd-line);border-radius:10px;padding:14px 16px 6px;margin:0 0 14px;min-width:0}
#bd-jcc legend{font-weight:700;padding:0 6px}
#bd-jcc .row{display:grid;grid-template-columns:1fr 1fr;gap:10px 16px}
@media (max-width:560px){#bd-jcc .row{grid-template-columns:1fr}}
#bd-jcc label{display:block;font-size:.92em;margin-bottom:10px}
#bd-jcc .hint{display:block;opacity:.7;font-size:.88em}
#bd-jcc input,#bd-jcc select{width:100%;padding:8px 10px;margin-top:4px;border:1px solid var(--bd-line);border-radius:6px;font:inherit;background:transparent;color:inherit}
#bd-jcc select option{color:#111}
#bd-jcc .inline{display:flex;gap:8px}
#bd-jcc .inline input{flex:1;min-width:0}
#bd-jcc .inline select{width:auto;flex:0 0 auto}
#bd-jcc .seg{display:flex;flex-wrap:wrap;gap:8px;margin:2px 0 12px;border:0;padding:0}
#bd-jcc .seg label{display:flex;align-items:center;gap:6px;margin:0;padding:8px 14px;border:1px solid var(--bd-line);border-radius:999px;cursor:pointer;font-size:.95em}
#bd-jcc .seg input{width:auto;margin:0;accent-color:var(--bd-red)}
#bd-jcc .seg label:has(input:checked){border-color:var(--bd-red);background:var(--bd-soft);font-weight:700}
#bd-jcc .result{border:2px solid var(--bd-red);border-radius:10px;padding:14px 16px;background:var(--bd-soft)}
#bd-jcc .total{font-size:1.7em;font-weight:700;margin:0;line-height:1.2}
#bd-jcc .sub{margin:2px 0 6px}
#bd-jcc .each{font-weight:700;margin:0 0 6px}
#bd-jcc table{width:100%;border-collapse:collapse;margin:8px 0}
#bd-jcc td,#bd-jcc th{padding:5px 0;border-bottom:1px solid var(--bd-line);text-align:left;font-weight:normal}
#bd-jcc td:last-child,#bd-jcc th:last-child{text-align:right;font-variant-numeric:tabular-nums;white-space:nowrap;padding-left:12px}
#bd-jcc caption{text-align:left;font-weight:700;padding:10px 0 2px}
#bd-jcc details{margin-top:8px}
#bd-jcc summary{cursor:pointer;font-weight:700}
#bd-jcc pre{white-space:pre-wrap;font-size:.85em;margin:8px 0 0;background:transparent;border:0;padding:0}
#bd-jcc .note{font-size:.85em;opacity:.75;margin:10px 0 0}
#bd-jcc .warn{color:var(--bd-red);font-weight:700}
</style>
<fieldset>
<legend>Your journey</legend>
<div class="row">
<label>Distance
<span class="inline"><input id="bd-jc-dist" type="number" min="0" step="any" value="100" inputmode="decimal"><select id="bd-jc-dunit" aria-label="Distance unit"><option value="mi">miles</option><option value="km">km</option></select></span>
<span class="hint">One way. Google Maps or your sat nav shows it.</span></label>
<label>Trip
<select id="bd-jc-trip"><option value="1">One way</option><option value="2">Return (there and back)</option></select></label>
<label>People sharing the cost
<input id="bd-jc-people" type="number" min="1" step="1" value="1" inputmode="numeric">
<span class="hint">Include the driver if they pay a share.</span></label>
<label>Other costs (£)
<input id="bd-jc-extras" type="number" min="0" step="0.01" value="0" inputmode="decimal">
<span class="hint">Parking, tolls, crossings, clean air zones. For the whole trip.</span></label>
</div>
</fieldset>
<fieldset>
<legend>Your car</legend>
<div class="seg" role="radiogroup" aria-label="Fuel">
<label><input type="radio" name="bd-jc-fuel" value="petrol" checked> Petrol or hybrid</label>
<label><input type="radio" name="bd-jc-fuel" value="diesel"> Diesel</label>
<label><input type="radio" name="bd-jc-fuel" value="electric"> Electric</label>
</div>
<div class="row" id="bd-jc-ice">
<label>Fuel economy
<span class="inline"><input id="bd-jc-eco" type="number" min="0" step="any" value="45" inputmode="decimal"><select id="bd-jc-ecounit" aria-label="Fuel economy unit"><option value="mpg">mpg</option><option value="l100">litres per 100 km</option></select></span>
<span class="hint">Your trip computer shows it. Many family cars do 40 to 55 mpg (5 to 7 litres per 100 km).</span></label>
<label>Fuel price (pence per litre)
<input id="bd-jc-price" type="number" min="0" step="0.1" value="175.3" inputmode="decimal">
<span class="hint" id="bd-jc-pricehint"></span></label>
</div>
<div class="row" id="bd-jc-ev" hidden>
<label>Efficiency (miles per kWh)
<input id="bd-jc-mpk" type="number" min="0" step="0.1" value="3.5" inputmode="decimal">
<span class="hint">Most electric cars manage 3 to 4 miles per kWh, and less in winter.</span></label>
<label>Where you charge
<select id="bd-jc-where"><option value="home">At home</option><option value="rapid">Public rapid charger</option><option value="slow">Public slow or fast charger</option><option value="own">My own price</option></select></label>
<label>Electricity price (pence per kWh)
<input id="bd-jc-kwh" type="number" min="0" step="0.01" value="26.32" inputmode="decimal">
<span class="hint" id="bd-jc-kwhhint"></span></label>
</div>
</fieldset>
<div class="result" aria-live="polite">
<p class="total" id="bd-jc-total">£0.00</p>
<p class="sub" id="bd-jc-sub"></p>
<p class="each" id="bd-jc-each" hidden></p>
<table><tbody id="bd-jc-lines"></tbody></table>
<table><caption>The same trip in a typical car</caption><tbody id="bd-jc-compare"></tbody></table>
<details><summary>Show the working</summary><pre id="bd-jc-working"></pre></details>
<p class="note" id="bd-jc-note"></p>
</div>
<p class="bd-credit" style="font-size:.85em;opacity:.75;margin:10px 0 0">Journey cost calculator by <a href="https://braindumps.co.uk/journey-cost-calculator/">Braindumps.co.uk</a></p>
<script>
(function () {
"use strict";
/* BEGIN CALC */
var LITRES_PER_GALLON = 4.54609; // UK gallon
var KM_PER_MILE = 1.609344;
function journeyCost(o) {
var miles = (o.unit === "km" ? o.distance / KM_PER_MILE : o.distance) * o.trips;
var r = { miles: miles, km: miles * KM_PER_MILE, litres: 0, kwh: 0, energyPence: 0 };
if (o.fuel === "electric") {
r.kwh = o.milesPerKwh > 0 ? miles / o.milesPerKwh : 0;
r.energyPence = r.kwh * o.pencePerKwh;
} else {
var litresPerMile = 0;
if (o.ecoUnit === "l100") { litresPerMile = o.eco * KM_PER_MILE / 100; }
else if (o.eco > 0) { litresPerMile = LITRES_PER_GALLON / o.eco; }
r.litres = miles * litresPerMile;
r.energyPence = r.litres * o.pencePerLitre;
}
r.fuelCost = r.energyPence / 100;
r.extras = o.extras;
r.total = r.fuelCost + o.extras;
r.people = Math.max(1, Math.floor(o.people) || 1);
r.each = r.total / r.people;
r.pencePerMile = miles > 0 ? r.energyPence / miles : 0;
return r;
}
/* END CALC */
// UK averages. Update these when prices change.
var PRICES = {
petrol: { p: 175.3, label: "UK average petrol price, week of 12 October 2026." },
diesel: { p: 200.0, label: "UK average diesel price, week of 12 October 2026." },
home: { p: 26.32, label: "Energy price cap for England, Scotland and Wales, 1 October to 31 December 2026." },
rapid: { p: 79, label: "UK pay-as-you-go average for rapid chargers, September 2026." },
slow: { p: 54, label: "UK pay-as-you-go average for slow and fast chargers, September 2026." }
};
var TYPICAL = { petrol: 45, diesel: 52, electric: 3.5 };
var root = document.getElementById("bd-jcc");
if (!root) { return; }
function el(id) { return document.getElementById(id); }
function num(id) { var v = parseFloat(el(id).value); return isFinite(v) && v >= 0 ? v : 0; }
function money(v) { return "£" + v.toFixed(2); }
function fixed(v, d) { return v.toLocaleString("en-GB", { minimumFractionDigits: d, maximumFractionDigits: d }); }
function fuel() { var c = root.querySelector('input[name="bd-jc-fuel"]:checked'); return c ? c.value : "petrol"; }
var edited = {};
["bd-jc-eco", "bd-jc-price", "bd-jc-mpk", "bd-jc-kwh"].forEach(function (id) {
el(id).addEventListener("input", function () { edited[id] = true; });
});
function readInputs(f) {
return {
distance: num("bd-jc-dist"), unit: el("bd-jc-dunit").value, trips: parseInt(el("bd-jc-trip").value, 10) || 1,
fuel: f, eco: num("bd-jc-eco"), ecoUnit: el("bd-jc-ecounit").value, pencePerLitre: num("bd-jc-price"),
milesPerKwh: num("bd-jc-mpk"), pencePerKwh: num("bd-jc-kwh"), people: num("bd-jc-people"), extras: num("bd-jc-extras")
};
}
function row(tbody, a, b) {
var tr = document.createElement("tr");
var td1 = document.createElement("td"); td1.textContent = a;
var td2 = document.createElement("td"); td2.textContent = b;
tr.appendChild(td1); tr.appendChild(td2); tbody.appendChild(tr);
}
function update() {
var f = fuel();
var o = readInputs(f);
var r = journeyCost(o);
var ev = f === "electric";
var missing = ev ? o.milesPerKwh <= 0 : o.eco <= 0;
var tripWord = o.trips === 2 ? "return" : "one way";
el("bd-jc-total").textContent = money(r.total);
el("bd-jc-sub").textContent = "for " + fixed(r.miles, r.miles < 10 ? 1 : 0) + " miles (" + tripWord + ")" + (o.extras > 0 ? ", including " + money(o.extras) + " of other costs" : "");
el("bd-jc-each").hidden = r.people < 2;
el("bd-jc-each").textContent = money(r.each) + " each for " + r.people + " people";
var lines = el("bd-jc-lines"); lines.textContent = "";
if (ev) { row(lines, "Electricity used", fixed(r.kwh, 1) + " kWh"); row(lines, "Charging cost", money(r.fuelCost)); }
else { row(lines, "Fuel used", fixed(r.litres, 1) + " litres (" + fixed(r.litres / LITRES_PER_GALLON, 1) + " gallons)"); row(lines, "Fuel cost", money(r.fuelCost)); }
row(lines, ev ? "Cost per mile (charging)" : "Cost per mile (fuel)", fixed(r.pencePerMile, 1) + "p");
if (o.extras > 0) { row(lines, "Other costs", money(o.extras)); }
// The same distance in typical cars, at the prices above.
var cmp = el("bd-jc-compare"); cmp.textContent = "";
var base = { distance: o.distance, unit: o.unit, trips: o.trips, ecoUnit: "mpg", people: 1, extras: 0 };
var opts = [
["Petrol, " + TYPICAL.petrol + " mpg", { fuel: "petrol", eco: TYPICAL.petrol, pencePerLitre: PRICES.petrol.p }],
["Diesel, " + TYPICAL.diesel + " mpg", { fuel: "diesel", eco: TYPICAL.diesel, pencePerLitre: PRICES.diesel.p }],
["Electric, home charging", { fuel: "electric", milesPerKwh: TYPICAL.electric, pencePerKwh: PRICES.home.p }],
["Electric, rapid charger", { fuel: "electric", milesPerKwh: TYPICAL.electric, pencePerKwh: PRICES.rapid.p }]
];
opts.forEach(function (x) {
var c = journeyCost(Object.assign({}, base, x[1]));
row(cmp, x[0], money(c.fuelCost));
});
var w = [];
var oneWay = o.unit === "km" ? fixed(o.distance, 1) + " km = " + fixed(o.distance / KM_PER_MILE, 1) + " miles" : fixed(o.distance, 1) + " miles";
w.push("Distance = " + oneWay + (o.trips === 2 ? " x 2 (return) = " + fixed(r.miles, 1) + " miles" : ""));
if (ev) {
w.push("Electricity = " + fixed(r.miles, 1) + " miles / " + fixed(o.milesPerKwh, 1) + " miles per kWh = " + fixed(r.kwh, 2) + " kWh");
w.push("Charging cost = " + fixed(r.kwh, 2) + " kWh x " + fixed(o.pencePerKwh, 2) + "p = " + money(r.fuelCost));
} else if (o.ecoUnit === "l100") {
w.push("Fuel used = " + fixed(r.km, 1) + " km x " + fixed(o.eco, 1) + " litres / 100 km = " + fixed(r.litres, 2) + " litres");
w.push("Fuel cost = " + fixed(r.litres, 2) + " litres x " + fixed(o.pencePerLitre, 1) + "p = " + money(r.fuelCost));
} else {
w.push("Gallons used = " + fixed(r.miles, 1) + " miles / " + fixed(o.eco, 1) + " mpg = " + fixed(r.litres / LITRES_PER_GALLON, 3) + " gallons");
w.push("Litres used = gallons x 4.546 = " + fixed(r.litres, 2) + " litres");
w.push("Fuel cost = " + fixed(r.litres, 2) + " litres x " + fixed(o.pencePerLitre, 1) + "p = " + money(r.fuelCost));
}
if (o.extras > 0) { w.push("Other costs = " + money(o.extras)); }
w.push("Total = " + money(r.total));
if (r.people > 1) { w.push("Each = " + money(r.total) + " / " + r.people + " = " + money(r.each)); }
el("bd-jc-working").textContent = w.join("\n");
var note = el("bd-jc-note");
if (missing) { note.innerHTML = '<span class="warn">Enter your car’s ' + (ev ? "miles per kWh" : "fuel economy") + " to see the cost.</span>"; }
else { note.textContent = "Fuel economy changes with speed, traffic, load and weather, so treat the answer as a good estimate, not an exact figure."; }
}
function setFuel() {
var f = fuel();
var ev = f === "electric";
el("bd-jc-ice").hidden = ev;
el("bd-jc-ev").hidden = !ev;
if (!ev) {
if (!edited["bd-jc-price"]) { el("bd-jc-price").value = PRICES[f].p.toFixed(1); }
if (!edited["bd-jc-eco"] && el("bd-jc-ecounit").value === "mpg") { el("bd-jc-eco").value = TYPICAL[f]; }
el("bd-jc-pricehint").textContent = PRICES[f].label + " Change it to what you pay.";
}
update();
}
function setWhere() {
var w = el("bd-jc-where").value;
if (w !== "own") {
el("bd-jc-kwh").value = PRICES[w].p;
edited["bd-jc-kwh"] = false;
el("bd-jc-kwhhint").textContent = PRICES[w].label + " Change it to your own rate.";
} else {
el("bd-jc-kwhhint").textContent = "Enter the rate on your bill or charging app.";
el("bd-jc-kwh").focus();
}
update();
}
el("bd-jc-ecounit").addEventListener("change", function () {
// Convert the figure already entered so the answer stays the same.
var v = num("bd-jc-eco");
if (v > 0) {
var conv = 100 * LITRES_PER_GALLON / (KM_PER_MILE * v); // mpg <-> litres per 100 km uses the same formula both ways
var dp = el("bd-jc-ecounit").value === "l100" ? 100 : 10;
el("bd-jc-eco").value = Math.round(conv * dp) / dp;
}
update();
});
root.querySelectorAll('input[name="bd-jc-fuel"]').forEach(function (r) { r.addEventListener("change", setFuel); });
el("bd-jc-where").addEventListener("change", setWhere);
el("bd-jc-kwh").addEventListener("input", function () { el("bd-jc-where").value = "own"; el("bd-jc-kwhhint").textContent = "Your own rate."; });
root.addEventListener("input", update);
root.addEventListener("change", update);
el("bd-jc-kwhhint").textContent = PRICES.home.label + " Change it to your own rate.";
setFuel();
})();
</script>
</div>