angelsolaorbaiceta / kunits

Unit Conversion engine for the JVM

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

KUnits

Unit Conversion engine for the JVM.

Usage

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 {
    // ...
}

About

Unit Conversion engine for the JVM

License:MIT License


Languages

Language:Kotlin 100.0%