{
  "schemaVersion": 1,
  "slug": "energy-calculator",
  "category": "conversion",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "970185f3fe969abd2060bfbc2f4899ce16d3ead97c8bbc4ee178bec7f91b0cbd",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/energy-calculator.json",
    "src/engine.js"
  ],
  "runtimeSource": "/sources/engine.txt",
  "runtimeHash": "5c888d8898afbdee36267bb9977829e1e2ac568f6677c8ee87469c139864645c",
  "scope": "The compute function records implemented equations, constants, lookup tables and custom rules. Inputs record defaults and allowed values; outputs record precision and units. Defaults are examples, not recommendations. General background references are not evidence for this specific algorithm.",
  "publishedFormula": {
    "formula": "E_out = E_in × f_in ÷ f_out",
    "vars": [
      [
        "E_in",
        "Input energy"
      ],
      [
        "f_in",
        "Source factor in joules (J 1, cal 4.184, kcal 4184, Wh 3600, kWh 3.6×10⁶, BTU 1055.06)"
      ],
      [
        "f_out",
        "Target factor"
      ],
      [
        "E_out",
        "Converted energy"
      ]
    ],
    "note": "Also ft·lb 1.3558 and therm 1.055×10⁸; all factors are relative to the joule; pure unit conversion. `cal` means the thermochemical small calorie (4.184 J); 1 kcal = 1,000 cal. Food-label Calories are usually kilocalories."
  },
  "externalEvidence": {
    "reviewedAt": "2026-10-04",
    "sources": [
      {
        "name": "NIST SP 811 — Conversion factors by quantity",
        "url": "https://www.nist.gov/pml/special-publication-811/nist-guide-si-appendix-b-conversion-factors/nist-guide-si-appendix-b9"
      }
    ],
    "basis": "Convert energy via joules; watt-hour = 3600 J.",
    "limitations": "Only the displayed unit definitions are converted; rounding and measurement uncertainty are separate.",
    "implementationHash": "970185f3fe969abd2060bfbc2f4899ce16d3ead97c8bbc4ee178bec7f91b0cbd",
    "domain": "conversion"
  },
  "contract": {
    "compute": "const units={\"j\":\"J\",\"kj\":\"kJ\",\"cal\":\"cal\",\"kcal\":\"kcal\",\"wh\":\"Wh\",\"kwh\":\"kWh\",\"btu\":\"BTU\",\"ftlb\":\"ft·lb\",\"therm\":\"therm\"}, factors={\"j\":1,\"kj\":1000,\"cal\":4.184,\"kcal\":4184,\"wh\":3600,\"kwh\":3600000,\"btu\":1055.05585262,\"ftlb\":1.3558179483314,\"therm\":105505585.257348}; if(!Number.isFinite(value)||value<-1000000000000||value>1000000000000||!Object.prototype.hasOwnProperty.call(units,from)||!Object.prototype.hasOwnProperty.call(units,to))return {\"result\":null,\"joules\":null,\"kcal\":null,\"kwh\":null,\"__error\":\"inputError\"}; const out=(function(){const F={j:1,kj:1000,cal:4.184,kcal:4184,wh:3600,kwh:3600000,btu:1055.05585262,ftlb:1.3558179483314,therm:105505585.257348}; const j=value*F[from]; return { result: j/F[to], joules: j, kcal: j/4184, kwh: j/3600000 };})(); if(out.__error)return {...{\"result\":null,\"joules\":null,\"kcal\":null,\"kwh\":null},...out}; out.__resultUnit=units[to]; out.__unitRatio=factors[to]/factors[from]; return out;",
    "inputs": [
      {
        "name": "value",
        "type": "number",
        "default": 1,
        "min": -1000000000000,
        "max": 1000000000000,
        "step": 0.0001,
        "requiredValue": true,
        "strictRange": true
      },
      {
        "name": "from",
        "type": "select",
        "default": "kcal",
        "options": [
          {
            "value": "kcal"
          },
          {
            "value": "j"
          },
          {
            "value": "kj"
          },
          {
            "value": "cal"
          },
          {
            "value": "wh"
          },
          {
            "value": "kwh"
          },
          {
            "value": "btu"
          },
          {
            "value": "ftlb"
          },
          {
            "value": "therm"
          }
        ]
      },
      {
        "name": "to",
        "type": "select",
        "default": "kj",
        "options": [
          {
            "value": "kj"
          },
          {
            "value": "j"
          },
          {
            "value": "cal"
          },
          {
            "value": "kcal"
          },
          {
            "value": "wh"
          },
          {
            "value": "kwh"
          },
          {
            "value": "btu"
          },
          {
            "value": "ftlb"
          },
          {
            "value": "therm"
          }
        ]
      },
      {
        "name": "precision",
        "type": "select",
        "default": 4,
        "options": [
          {
            "value": 0
          },
          {
            "value": 2
          },
          {
            "value": 4
          },
          {
            "value": 6
          }
        ]
      }
    ],
    "outputs": [
      {
        "name": "result",
        "precision": 4,
        "unit": "",
        "precisionField": "precision",
        "unitField": "__resultUnit",
        "trimTrailingZeros": true,
        "notation": "auto"
      },
      {
        "name": "joules",
        "precision": 2,
        "unit": "J",
        "showWhen": {
          "to": [
            "kj",
            "cal",
            "kcal",
            "wh",
            "kwh",
            "btu",
            "ftlb",
            "therm"
          ]
        },
        "notation": "auto"
      },
      {
        "name": "kcal",
        "precision": 4,
        "unit": "kcal",
        "showWhen": {
          "to": [
            "j",
            "kj",
            "cal",
            "wh",
            "kwh",
            "btu",
            "ftlb",
            "therm"
          ]
        },
        "notation": "auto"
      },
      {
        "name": "kwh",
        "precision": 6,
        "unit": "kWh",
        "showWhen": {
          "to": [
            "j",
            "kj",
            "cal",
            "kcal",
            "wh",
            "btu",
            "ftlb",
            "therm"
          ]
        },
        "notation": "auto"
      }
    ],
    "interpret": null
  }
}
