Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Java Unit Converter

Maven Central

Lightweight Java library for converting values and doing arithmetic inside the same measurement category.

Supports Java 8 and above.


✨ Features

  • Length: metric, imperial, marine, and other common units
  • Weight: metric and imperial units
  • Temperature: Kelvin, Celsius, Fahrenheit, and Rankine
  • Data size: decimal and binary bit/byte units
  • Bit rate: decimal and binary bit/byte-per-second units

Core Capabilities

  • Convert between supported units within the same category
  • Perform arithmetic operations: addition, subtraction, multiplication, division
  • Format values in any desired unit type

📦 Maven Usage

Add the dependency to your pom.xml:

<dependency>
    <groupId>dev.ercan</groupId>
    <artifactId>unit-converter</artifactId>
    <version>1.0.1</version>
</dependency>

📖 Usage Examples

Example 1: Length

import dev.ercan.unit.converter.length.Length;
import dev.ercan.unit.converter.length.LengthUnit;

Length distance = Length.of(1, LengthUnit.KILOMETER)
    .plus(250, LengthUnit.METER)
    .minus(10, LengthUnit.FOOT);

String formatted = distance.format(LengthUnit.METER); // "1246.95 m"

Example 2: Weight

import dev.ercan.unit.converter.weight.Weight;
import dev.ercan.unit.converter.weight.WeightUnit;

Weight weight = Weight.parse("3 kg")
    .plus(250, WeightUnit.GRAM);

String formatted = weight.format(WeightUnit.GRAM); // "3250 gr"

Example 3: Temperature

import dev.ercan.unit.converter.temperature.Temperature;
import dev.ercan.unit.converter.temperature.TemperatureUnit;

Temperature temperature = Temperature.ofCelsius(20)
    .plus(18, TemperatureUnit.FAHRENHEIT);

String celsius = temperature.format(TemperatureUnit.CELSIUS); // "30 °C"

Example 4: DataSize

import dev.ercan.unit.converter.data.size.DataSize;
import dev.ercan.unit.converter.data.size.DataSizeUnit;

DataSize size = DataSize.of(2, DataSizeUnit.MEBIBYTE);
String formatted = size.format(DataSizeUnit.KIBIBYTE); // "2048 KiB"

Example 5: BitRate

import dev.ercan.unit.converter.data.transfer.BitRate;
import dev.ercan.unit.converter.data.transfer.BitRateUnit;

BitRate bitRate = BitRate.of(100, BitRateUnit.MEBIBIT)
    .multipliedBy(4)
    .dividedBy(2);

String formatted = bitRate.format(BitRateUnit.MEBIBIT); // "200 Mibps"

🤝 Contributing

Contributions are welcome! Feel free to fork the repo, submit pull requests or open issues.


📄 License

This project is licensed under the MIT License.

About

Lightweight Java library for converting values and doing arithmetic inside the same measurement category.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages