<dependencies> <dependency> <groupId>javax.measure</groupId> <artifactId>unit-api</artifactId> <version>1.0.1</version> </dependency> <dependency> <groupId>tec.uom.se</groupId> <artifactId>uom-se</artifactId> <version>1.1.1</version> </dependency> </dependencies> import javax.measure.Unit; import javax.measure.quantity.Length; import tech.uom.se.unit.Units; Unit<Length> foot = Units.METRE.multiply(0.3048).asType(Length.class); import javax.measure.Quantity; import javax.measure.Unit; import javax.measure.quantity.Length; import tech.uom.se.unit.Units; import tech.units.indriya.quantity.Quantities; import tech.units.indriya.unit.Units; public class UnitConversionExample { public static void main(String[] args) { Unit<Length> meter = Units.METRE; Quantity<Length> length = Quantities.getQuantity(10, meter); Unit<Length> foot = Units.FOOT; Quantity<Length> convertedLength = length.to(foot); } } import javax.measure.Quantity; import javax.measure.Unit; import javax.measure.quantity.Length; import tech.uom.se.unit.Units; import tech.units.indriya.quantity.Quantities; public class UnitCalculationExample { public static void main(String[] args) { Unit<Length> meter = Units.METRE; Quantity<Length> length1 = Quantities.getQuantity(10, meter); Unit<Length> foot = Units.FOOT; Quantity<Length> length2 = Quantities.getQuantity(30, foot); Quantity<Length> sum = length1.add(length2); } } - [Units of Measurement API Specification](https://unitsofmeasurement.github.io/api/) - [Units of Measurement API GitHub Repository](https://github.com/unitsofmeasurement/uom-se)


上一篇:
下一篇:
切换中文