Search code examples
jsr363

unit conversion between mile and km using jsr 363 library


Hi I am new to using jsr 363 to do a unit conversion application. Can anyone help me to do the conversion between mile and km using jsr 363 library(uni-api)


Solution

  • It's done like this:

    Quantity<Length> len = Quantities.getQuantity(10, MetricPrefix.KILO(Units.METRE));
    Quantity<Length> mile = len.to(USCustomary.MILE);
    

    You'll find examples for using the Common systems (including USCustomary) under https://github.com/unitsofmeasurement/uom-demos/tree/master/console/systems/common

    Cheers, Werner