there is a specific JSR 275 (javax.measure) with JScience as RI (Reference Implementation). For example converting 100 Miles to kilometers is easy as:
UnitConverter toKilometers = MILE.getConverterTo(KILOMETER);
double km = toKilometers.convert(Measure.valueOf(100, MILE).doubleValue(MILE));
(note that units are all type safe a compile-time, a killer feature imho)
The reverse can be easy:
UnitConverter toMiles1 = KILOMETER.getConverterTo(MILE);
or supereasy as:
UnitConverter toMiles2 = toKilometers.inverse();
NB imports:
import javax.measure.Measure;
import javax.measure.converter.UnitConverter;
import javax.measure.quantity.Length;
import static javax.measure.unit.NonSI.*;
import static javax.measure.unit.SI.*;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…