{
  "id": "gas",
  "version": "a72cd4680f30",
  "status": "published",
  "name": "Gas Calculator",
  "question": "How much will gas cost?",
  "summary": "Computes the fuel a trip uses and what it costs from the distance, the fuel economy in mpg, L/100 km or km/L, and the price per gallon or litre, with a round trip and a split between people.",
  "category": "everyday-life",
  "url": "https://www.acalculator.org/everyday-life/gas-calculator",
  "markdown": "https://www.acalculator.org/everyday-life/gas-calculator.md",
  "kind": "function",
  "method": "fuel = distance ÷ fuel economy (or distance × L/100 km ÷ 100); cost = fuel × price per unit of fuel",
  "assumptions": [
    "The fuel economy is the car’s average for the trip. Speed, load, traffic and weather change it.",
    "mpg is miles per US gallon (3.785411784 L). L/100 km and km/L are converted exactly.",
    "The default price is the US average for regular gasoline in the week of September 21, 2026, from the EIA. Type your local price."
  ],
  "inputs": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "dist": {
        "title": "Distance",
        "description": "How far the trip is, one way.",
        "type": [
          "number",
          "string"
        ],
        "x-quantity": "length",
        "minimum": 0,
        "maximum": 1000000000
      },
      "round": {
        "title": "Round trip",
        "description": "Count the distance twice, there and back.",
        "type": "boolean"
      },
      "econ": {
        "title": "Fuel economy",
        "description": "How far the car goes on its fuel, in the unit chosen next.",
        "type": "number",
        "minimum": 0.1,
        "maximum": 1000
      },
      "econUnit": {
        "title": "Fuel economy unit",
        "description": "Miles per US gallon, litres per 100 kilometres, or kilometres per litre.",
        "type": "string",
        "enum": [
          "mpg",
          "l100km",
          "kml"
        ]
      },
      "price": {
        "title": "Fuel price",
        "description": "The price of the fuel per gallon or per litre.",
        "type": "number",
        "x-unit": "USD",
        "minimum": 0,
        "maximum": 1000
      },
      "per": {
        "title": "Price per",
        "description": "Whether the price is per US gallon or per litre.",
        "type": "string",
        "enum": [
          "gal",
          "L"
        ]
      },
      "people": {
        "title": "Split between",
        "description": "How many people share the cost.",
        "type": "integer",
        "minimum": 1,
        "maximum": 100
      }
    }
  },
  "outputs": {
    "cost": {
      "label": "Fuel cost",
      "description": "The fuel used × the price.",
      "format": "money"
    },
    "fuel": {
      "label": "Fuel used",
      "description": "The distance ÷ the fuel economy.",
      "format": "quantity",
      "unit": "gal"
    },
    "liters": {
      "label": "Fuel used (litres)",
      "description": "The fuel used in litres.",
      "format": "quantity",
      "unit": "L"
    },
    "share": {
      "label": "Cost per person",
      "description": "The fuel cost ÷ the number of people.",
      "format": "money"
    },
    "total": {
      "label": "Distance driven",
      "description": "The distance, doubled for a round trip.",
      "format": "quantity",
      "unit": "mi"
    }
  },
  "defaultAnswer": {
    "inputs": {
      "dist": 402336,
      "round": false,
      "econ": 25,
      "econUnit": "mpg",
      "price": 4.478,
      "per": "gal",
      "people": 1
    },
    "outputs": {
      "cost": 44.78,
      "fuel": 0.03785411784,
      "liters": 0.03785411784,
      "share": 44.78,
      "total": 402336
    },
    "text": "Driving 250 mi uses 10 gal of fuel, which costs $44.78."
  },
  "examples": [
    {
      "given": {
        "dist": 24140160,
        "round": false,
        "econ": 20,
        "econUnit": "mpg",
        "price": 3.6,
        "per": "gal",
        "people": 1
      },
      "expect": {
        "fuel": 2.839058838,
        "cost": 2700
      },
      "source": "fueleconomy.gov, Fuel Economy Savings Calculator (cited in content.mdx): 15,000 miles at 20 mpg and $3.60 a gallon; 15,000 ÷ 20 = 750 gal × $3.60 = $2,700 (hand calculation in content.mdx)",
      "tolerance": 1e-12
    },
    {
      "given": {
        "dist": 24140160,
        "round": false,
        "econ": 30,
        "econUnit": "mpg",
        "price": 3.6,
        "per": "gal",
        "people": 1
      },
      "expect": {
        "fuel": 1.8927058920000002,
        "cost": 1800
      },
      "source": "fueleconomy.gov, Fuel Economy Savings Calculator: the 30 mpg car costs $900 less a year than the 20 mpg car; 15,000 ÷ 30 = 500 gal × $3.60 = $1,800",
      "tolerance": 1e-12
    },
    {
      "given": {
        "dist": 300000,
        "round": true,
        "econ": 7.5,
        "econUnit": "l100km",
        "price": 1.8,
        "per": "L",
        "people": 3
      },
      "expect": {
        "fuel": 0.045,
        "cost": 81,
        "share": 27
      },
      "source": "hand calculation in content.mdx: 600 km × 7.5 ÷ 100 = 45 L; × $1.80 = $81; ÷ 3 = $27",
      "tolerance": 1e-12
    },
    {
      "given": {
        "dist": 120000,
        "round": false,
        "econ": 15,
        "econUnit": "kml",
        "price": 4.478,
        "per": "gal",
        "people": 1
      },
      "expect": {
        "fuel": 0.008,
        "cost": 9.463699603678307
      },
      "source": "hand calculation in content.mdx: 120 ÷ 15 = 8 L = 2.113 gal; × $4.478 = $9.46"
    }
  ],
  "sources": [
    "U.S. Department of Energy and U.S. EPA, fueleconomy.gov, Fuel Economy Savings Calculator: fuel cost = miles ÷ mpg × price per gallon. https://www.fueleconomy.gov/feg/savemoney.jsp",
    "U.S. Energy Information Administration, Gasoline and Diesel Fuel Update: US regular gasoline $4.478 a gallon, week of September 21, 2026. https://www.eia.gov/petroleum/gasdiesel/",
    "NIST SP 811 (2008), Appendix B: 1 US gallon = 3.785411784 L exactly; 1 mi = 1.609344 km exactly."
  ],
  "related": [
    "electricity-cost",
    "tire-size"
  ],
  "changelog": []
}
