PHPackages                             khaledalam/unit - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. khaledalam/unit

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

khaledalam/unit
===============

A PHP library for unit conversions and quantity operations

v1.0.2(10mo ago)531MITPHPPHP ^8.2CI passing

Since Jul 6Pushed 10mo agoCompare

[ Source](https://github.com/khaledalam/unit)[ Packagist](https://packagist.org/packages/khaledalam/unit)[ RSS](/packages/khaledalam-unit/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (1)Versions (4)Used By (0)

Unit
====

[](#unit)

[![Latest Stable Version](https://camo.githubusercontent.com/0d13b65a85c02ae7d605c22b6c97f2dcb4b29fbfe470c4219953cf877a5a09e1/68747470733a2f2f706f7365722e707567782e6f72672f6b68616c6564616c616d2f756e69742f76)](https://packagist.org/packages/KhaledAlam/Unit)[![Push](https://github.com/KhaledAlam/Unit/actions/workflows/push.yml/badge.svg)](https://github.com/KhaledAlam/Unit/actions/workflows/push.yml)[![codecov](https://camo.githubusercontent.com/078e154e8082357815de8592b915ee0dcea33d854e701b893723f4d1007e190f/68747470733a2f2f636f6465636f762e696f2f67682f4b68616c6564416c616d2f556e69742f67726170682f62616467652e7376673f746f6b656e3d344d494d324c52505244)](https://codecov.io/gh/KhaledAlam/Unit)[![License](https://camo.githubusercontent.com/2de47a15ff05cc64e5acbe0db58b16ebf298c90bc8bd90231bc59693e34ef6d0/68747470733a2f2f706f7365722e707567782e6f72672f6b68616c6564616c616d2f756e69742f6c6963656e7365)](https://packagist.org/packages/khaledalam/unit)

### PHP Units &amp; Dimensions Library

[](#php-units--dimensions-library)

A lightweight, type-safe PHP library for working with **quantities**, **units**, and **dimensional analysis**. Inspired by scientific computing needs, this library lets you define units, register them globally, perform arithmetic with dimension checking, and convert across compatible units.

---

Features
--------

[](#features)

- Immutable objects
- Dimensionally-aware arithmetic (`add`, `subtract`, `multiply`, `divide`)
- Automatic conversion between compatible units (e.g., cm to m)
- Support for compound units (e.g., m/s, kg⋅m²/s²)
- Enum-powered unit naming (`Name` enum)
- Custom unit registry

---

Installation
------------

[](#installation)

```
composer require khaledalam/unit
```

---

Basic Usage
-----------

[](#basic-usage)

```
