TNT.....: 4 kJ/gram and 7 MJ/liter
Gasoline: 43 kJ/gram and 33 MJ/literInteresting discussions about energetics are best had from a distance.
Edit: Or, a fair closed-system comparison to a battery would need to include a liquid oxygen tank or similar so you have the two components stored but can control the delivery...
As a stupid example, if we have a high density battery technology that never explodes unless, say, under magnetic forces only seen being produced by magnetars, that's a pretty safe battery.
eeeh that still doesn't matter really. Gasoline is safe(r) because it needs conditions to explode (spreading into area then ignition), instead of just detonator. Diesel even more so
A damaged gasoline tank that's near empty might explode but more likely it will just leak and start burning, and probably at that moment be still extinguishable. Explosives, well, you won't have time to blink.
Batteries ? Zero chance to extinguish, gonna let it burn thru. THAT is the problem
The fuels which afford the highest rates of storage tend to release it more slowly. Chemical explosives typically have about 1/10 the energy storage capacity (by mass) of fuels, as several people have pointed out.
Similar relationships exist for other forms of energy storage. For electricity, fuel cells, chemical cells ("batteries"), flywheel / reaction storage, and capacitors tend to offer a trade-off between total storage capacity and reaction time. Capacitors can react at intra-phase rates (that is, within a single 60Hz power cycle), whilst batteries and flywheels can take longer to come online.
See for example: "Battery Parameters" <https://www.monolithicpower.com/en/learning/mpscholar/batter...>.
Energy density of gasoline is approximately 44 to 45 megajoules per kilogram.
Energy density of TNT is approximately 4.184 megajoules per kilogram.
https://en.wikipedia.org/wiki/Table_of_explosive_detonation_...
There is a way how to use the energy density of gasoline for explosive purposes, Thermobaric weapons.
"A fuel–air explosive (FAE) device consists of a container of fuel and two separate explosive charges. After the munition is dropped or fired, the first explosive charge bursts open the container at a predetermined height and disperses the fuel in a cloud that mixes with atmospheric oxygen (the size of the cloud varies with the size of the munition). The cloud of fuel flows around objects and into structures. The second charge then detonates the cloud and creates a massive blast wave."