Energy
Represents an energy value.
This value class provides a type-safe way to handle energy, primarily in watt-hours (Wh) and kilowatt-hours (kWh). It supports basic arithmetic operations and comparisons.
Instances of Energy are created using the extension properties on Number, such as 100.wattHours or 2.5.kiloWattHours.
Example usage:
val batteryCapacity = 100.kiloWattHours
val energyConsumed = 25000.wattHours
val remainingEnergy = batteryCapacity - energyConsumed
println("Remaining energy: ${remainingEnergy.inKiloWattHours} kWh")Content copied to clipboard
The internal representation is in watt-hours as a Double to maintain precision for calculations, but exposed values like inWattHours are rounded to the nearest integer.