An energy conversion calculator should convert a supplied energy quantity with an explicit unit definition. It should not invent operating time, a tariff, a nutritional interpretation or a measurement record.
This original helper accepts J, kJ, MJ, Wh, kWh, thermochemical calories and International Table calories. The worked examples provide checks for the local HTML file; verify its controls in the intended host.

Use definitions rather than a generic calorie button
NIST lists different joule factors for thermochemical and International Table calories, alongside watt-hour and kilowatt-hour factors. Select those named entries deliberately. NIST: Energy Conversion Factors
| Accepted energy unit | Factor into joules |
|---|---|
| J | 1 |
| kJ | 1,000 |
| MJ | 1,000,000 |
| Wh | 3,600 |
| kWh | 3,600,000 |
| Thermochemical calorie, cal_th | 4.184 |
| International Table calorie, cal_IT | 4.1868 |
Keep cal_th and cal_IT as distinct internal IDs and full visible labels. Generic calorie is unresolved until the source definition is known. This bounded tool does not infer a nutrition Calorie, add kilocalories, or adopt other calorie definitions by spelling similarity.
Likewise, BTU and eV are outside this whitelist. Their omission does not deny that they are energy units; it avoids extending a source table without the additional definition and precision review that those choices need.
Check the quantity's dimension first
Wh and kWh are energy units here. W and kW are power, so the tool rejects them as input units. A value of 250 kW does not become 250 Wh merely by selecting an energy destination.
No duration field exists in this design. The helper therefore cannot recover energy from a power rating. The error should ask for an energy quantity or a separately established duration-based calculation, rather than quietly introducing a time assumption.
This distinction also keeps the output honest: converting 250 Wh does not calculate electricity cost, emissions or savings. Those require additional records and definitions beyond a unit factor.
Inspect the arithmetic through a joule base
For accepted quantity x, calculate result = x × source joule factor ÷ destination joule factor. Use one intermediate joule value, preserving the original input and unit definition.
| Original independent example | Calculation/result |
|---|---|
| 1 kWh → J | 1 × 3,600,000 = 3,600,000 J |
| 1 kWh → MJ | 3,600,000 ÷ 1,000,000 = 3.6 MJ |
| 250 Wh → J | 250 × 3,600 = 900,000 J |
| 250 Wh → MJ | 900,000 ÷ 1,000,000 = 0.9 MJ |
| 250 Wh → kWh | 900,000 ÷ 3,600,000 = 0.25 kWh |
| 1 cal_th → J | 4.184 J |
| 1 cal_IT → J | 4.1868 J |
The two calorie entries differ by 0.0028 J per named unit. That is a definition difference, not a dietary finding or an uncertainty estimate for a measured sample.
An original record E01 could preserve 250 Wh, destination kWh, factors 3,600 and 3,600,000, and derivation 250 × 3,600 ÷ 3,600,000 = 0.25. The record contains what the reader supplied; it does not claim the quantity was measured by an imported meter.
Preserve the calculation before formatting it
Use the declared factors with unrounded internal numeric results. Format the visible result to at most six decimals where needed, marking display approximation. Rounding is presentation, not the input to a later conversion. A tiny positive result must not be presented as an exact zero.
Same-unit conversion preserves the accepted quantity. Swap reverses the latest valid record's units and takes its internal result as the new calculated quantity. Label that origin visibly and revalidate finite/nonnegative value, source-range limit and whitelisted IDs.
Manual edits invalidate that record, clear the old result and disable Swap until Calculate succeeds again. Do not read a formatted result string containing separators, unit text or rounded digits as the next source quantity.
An inverse conversion using the same declared factors should return the original value within the chosen numeric tolerance. That test concerns the helper's implementation; it does not certify input measurement accuracy.
Define what an invalid record does
Accept manually entered dot-decimal values from 0 to 1,000,000,000 with up to six fractional digits. Trim outside whitespace but retain raw text in the output record. This local grammar excludes signs, commas and exponent notation, and rejects blank, nonfinite or unsupported values.
Zero is valid energy input and returns zero in any supported destination. Blank is missing input and shows no result. Do not use numeric coercion that treats an empty string as zero.
Keep source/target selectors initially unselected, with generic calorie and kW absent from accepted options. If an unsupported external value reaches the validator anyway, reject it and explain the dimension or definition issue.
Any change to quantity or units clears the old derivation. Reset returns empty input, unselected units, no conversion record, no Swap candidate and cleared feedback. Text results, factors and error messages need readable labels and keyboard access, with actual narrow-screen and assistive-technology tests still required.
Copy this prompt to specify the native converter
Create an original self-contained HTML/CSS/JavaScript supplied-energy converter, complete native source, factor/provenance record and manual test matrix. Reference https://www.nist.gov/pml/special-publication-811/nist-guide-si-appendix-b-conversion-factors/nist-guide-si-appendix-b9 for the selected printed factors. No APIs/network/storage, meter imports, tariff/cost/emissions/savings or nutritional interpretation.
Whitelist J, kJ, MJ, Wh, kWh, thermochemical calorie cal_th and International Table calorie cal_IT. Joule factors respectively: 1,1000,1000000,3600,3600000,4.184,4.1868. Use distinct calorie IDs/full labels and provenance. Generic calorie needs definition; do not add nutrition Calories, kilocalories, BTU, eV or other definitions. W/kW are power and unsupported without a separate duration-based task; never silently relabel them Wh/kWh.
Result=x×Ffrom/Fto through J. Fixtures: 1 kWh→3600000 J→3.6 MJ; 250 Wh→900000 J→0.9 MJ→0.25 kWh; 1 cal_th→4.184 J versus 1 cal_IT→4.1868 J. Difference 0.0028 J reflects named definitions only. E01 retains raw 250 Wh, target kWh, factors, source URL and complete derivation. No claimed measurement or dietary conclusion.
Native value/source/target/Calculate/Swap/Reset controls; selectors initially unselected. Manual input accepts digits with optional dot and up to six fractional digits, finite nonnegative quantity ≤1000000000. Trim surrounding whitespace but preserve raw input. Reject signs, commas, exponents, blank, nonfinite and unsupported units. Zero is valid, blank is not.
Keep unrounded internal intermediate/result. Display at most six decimals with approximation context and do not label rounded tiny positives exact zero. Same-unit identity returns the input unchanged. Swap reverses only the latest valid record's units and uses stored unrounded result, visibly labeled calculated input. Revalidate finite/sign/range/IDs; manual lexical precision does not round the internal candidate. Reject out-of-range Swap with explanation. Edits invalidate record/result and disable Swap until a new calculation. Reset empties fields, units, feedback and record.
Test all fixtures, both calorie definitions, generic-calorie/kW rejection, identity/zero, invalid grammar/range, stale results, unrounded Swap/tolerance round trips and Reset. Check keyboard, actual article width and 360 px without page overflow. Report performed versus proposed tests; no built converter, verified host or accessibility claim before testing. Native source and factor record remain authoritative; optional NOS explanation promises no export, saved calculations or automatic source updates.
Keep E01's definition with its output
Maintain the native file and factor table alongside E01's supplied quantity and derivation. For calorie records, the definition belongs in the result itself, not in a note the next reader must remember to find.
A prepared HTML explanation in NOS can present the energy-unit comparison and worked record; NOS supports HTML saving and rendering. Verify actual hosted Calculate/Swap/Reset behavior separately, and retain the maintained native source as the basis for the calculation.
Explore NOS with the energy record. The useful result changes units while preserving what energy quantity and definition the reader actually supplied.