Distance divided by efficiency gives fuel
Divide distance by fuel efficiency to get the fuel used, then multiply by the price. 100 miles at 28 MPG uses 3.57 gallons, about $12.50 at $3.50 a gallon. Litres per 100 km runs the other way: 100 km at 7 L/100 km uses 7 litres.
Turn on round trip and set trips per month to see commuting costs directly: 15 miles each way on 22 working days, at 28 MPG and $3.50 a gallon, comes to about $83 a month.
Electric vehicles use the same arithmetic: treat a kWh like a gallon, enter miles per kWh as efficiency and your price per kWh as the fuel price. Home charging in the US averages around 17 cents per kWh; public fast chargers often charge 40 to 60 cents.
Rated efficiency is not real efficiency
Official figures come from a standard test cycle. Traffic, hard acceleration, air conditioning, load and winter warm-up typically cost 10-20%. Track your own by dividing trip distance by litres filled.
Driving conditions dominate. City driving is much worse with constant stopping and starting; highways peak near 100 km/h. Use an average for mixed routes.
Fuel is not the whole cost of running a car. Insurance, road tax, servicing and depreciation often exceed it. Compare commuting options with those included.