Unit Conversion engine for the JVM.
Create an instance of the conversion engine:
val engine = UnitConversionEngine()
use it to convert between units without exception handling:
engine.convert(amount = 25.0, from = "N/cm2", to = "lbf/in2")
Or make it safer:
// Fails: there is no way to convert from Newtons to Inches
try {
engine.convert(amount = 2.0, from = "N", to = "in")
} catch (e: ConversionException) {
// ...
}
Or alternatively, you can first check if a given conversion is possible:
if (engine.canConvert(from = "N", to = "cm")) {
engine.convert(amount = 25.0, from = "N", to = "cm")
} else {
// ...
}