Overview
Java Unit Converter Library is a comprehensive Java library for unit conversion and arithmetic operations across multiple scientific and technical categories.
Built for Java 8+, it ensures compatibility with modern JVM environments and is published on Maven Central for easy integration.
Supported Categories & Units
Length Units
- Metric: nanometer (nm), micrometer (µm), millimeter (mm), centimeter (cm), decimeter (dm), meter (m), decameter (dam), hectometer (hm), kilometer (km), megameter (Mm)
- Imperial: thou (th), inch (in), foot (ft), yard (yd), mile (mi), league (lea)
- Marine: fathom (fm), nautical mile (nmi)
- Other: furlong (fur)
Weight Units
- Metric: nanogram (ng), microgram (µg), milligram (mg), gram (gr), kilogram (kg), tonne (t), megaton (Mt)
- Imperial: ounce (oz), pound (lb), stone (st), short ton (US ton), long ton (UK ton)
Temperature Units
- Kelvin (K), Celsius (°C), Fahrenheit (°F), Rankine (°R)
Data Size Units
- Decimal: bit (b), byte (B), kilobyte (KB), megabyte (MB), gigabyte (GB), terabyte (TB), petabyte (PB)
- Binary: kibibyte (KiB), mebibyte (MiB), gibibyte (GiB), tebibyte (TiB), pebibyte (PiB)
Bit Rate Units
- Decimal: bit per second (bps), byte per second (B/s), kilobit per second (kbps), megabit per second (Mbps), gigabit per second (Gbps), terabit per second (Tbps), petabit per second (Pbps)
- Binary: kibibit per second (Kibps), mebibit per second (Mibps), gibibit per second (Gibps), tebibit per second (Tibps), pebibit per second (Pibps)
- Byte-based: kilobyte per second (KB/s), megabyte per second (MB/s), gigabyte per second (GB/s), terabyte per second (TB/s), petabyte per second (PB/s), plus binary equivalents (KiB/s, MiB/s, GiB/s, TiB/s, PiB/s)
Core Features
- Convert seamlessly between supported units within each category
- Perform arithmetic operations: addition, subtraction, multiplication, division
- Format results in any desired unit type for clear output
Getting Started
<dependency>
<groupId>dev.ercan</groupId>
<artifactId>unit-converter</artifactId>
<version>1.0.1</version>
</dependency>
Example Usage
Length distance = Length.of(1, LengthUnit.KILOMETER)
.plus(250, LengthUnit.METER)
.minus(10, LengthUnit.FOOT);
String formatted = distance.format(LengthUnit.METER); // "1246.95 m"
Weight weight = Weight.parse("3 kg")
.plus(250, WeightUnit.GRAM);
String formatted = weight.format(WeightUnit.GRAM); // "3250 gr"
Temperature temperature = Temperature.ofCelsius(20)
.plus(18, TemperatureUnit.FAHRENHEIT);
String celsius = temperature.format(TemperatureUnit.CELSIUS); // "30 °C"
DataSize size = DataSize.of(2, DataSizeUnit.MEBIBYTE);
String formatted = size.format(DataSizeUnit.KIBIBYTE); // "2048 KiB"
BitRate bitRate = BitRate.of(100, BitRateUnit.MEBIBIT)
.multipliedBy(4)
.dividedBy(2);
String formatted = bitRate.format(BitRateUnit.MEBIBIT); // "200 Mibps"
License
This project is licensed under the MIT License.
Contributing
Contributions are welcome! Please open issues or submit pull requests via GitHub.