PHPackages                             jordanbrauer/unit-converter - 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. jordanbrauer/unit-converter

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

jordanbrauer/unit-converter
===========================

Convert standard units from one to another with this easy to use, lightweight package

0.9.0(2y ago)1281.2M↑32.1%40[9 issues](https://github.com/jordanbrauer/unit-converter/issues)[5 PRs](https://github.com/jordanbrauer/unit-converter/pulls)6MITPHPPHP ^7.3 || ^8.0CI failing

Since Nov 12Pushed 2y ago3 watchersCompare

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

READMEChangelog (10)Dependencies (4)Versions (25)Used By (6)

Unit Converter
==============

[](#unit-converter)

[![Latest Stable Version](https://camo.githubusercontent.com/69edc511939ff154355d51949df4a6a4d0928bcf67f159f85650c8fe4dc699cf/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a6f7264616e6272617565722f756e69742d636f6e7665727465723f636f6c6f723d323537656332266c6162656c3d737461626c65267374796c653d666c61742d737175617265)](https://packagist.org/packages/jordanbrauer/unit-converter)[![Latest Unstable Version](https://camo.githubusercontent.com/4990b290fb69dbbf13e845958f52982f7eb5632913080c04f20f89855995d244/68747470733a2f2f706f7365722e707567782e6f72672f6a6f7264616e6272617565722f756e69742d636f6e7665727465722f762f756e737461626c653f666f726d61743d666c61742d737175617265)](//packagist.org/packages/jordanbrauer/unit-converter)[![PHP from Packagist](https://camo.githubusercontent.com/f5c59dc104d6bae394c94a2b49aed182daed344f0347465a826fd1ba0b976e5b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6a6f7264616e6272617565722f756e69742d636f6e7665727465723f636f6c6f723d383839326265267374796c653d666c61742d737175617265)](https://secure.php.net/releases/)[![composer.lock available](https://camo.githubusercontent.com/fc70c7d41b626f40308131d8574e32a1ebd88e7f46d7057cb780f52373e163ef/68747470733a2f2f706f7365722e707567782e6f72672f6a6f7264616e6272617565722f756e69742d636f6e7665727465722f636f6d706f7365726c6f636b3f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/jordanbrauer/unit-converter)[![license](https://camo.githubusercontent.com/a257c0314fe99ddab879c573719a2355c66fa31b6fb5c9c745059ff5ffa00e5e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6a6f7264616e6272617565722f756e69742d636f6e7665727465722e7376673f7374796c653d666c61742d737175617265)](https://github.com/jordanbrauer/unit-converter/blob/master/LICENSE)

[![CI Workflow](https://camo.githubusercontent.com/2b5ce72bb1a314641549543434ff2363acdd8663fc05bb717755da0fce956f6d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6a6f7264616e6272617565722f756e69742d636f6e7665727465722f43493f7374796c653d666c61742d737175617265266c6162656c3d7465737473)](https://github.com/jordanbrauer/unit-converter/actions?query=workflow%3ACI)[![Code Maintainability](https://camo.githubusercontent.com/92e083f525f68247653f109d07ce2f59eb94db8d5daa527b19306af33145ed26/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636c696d6174652f6d61696e7461696e6162696c6974792f6a6f7264616e6272617565722f756e69742d636f6e7665727465722e7376673f7374796c653d666c61742d737175617265)](https://codeclimate.com/github/jordanbrauer/unit-converter)[![Code Coverage](https://camo.githubusercontent.com/199ec1f85489fd3efa198104bdd060676576e726e34519e628420f33fc946b89/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636c696d6174652f636f7665726167652f6a6f7264616e6272617565722f756e69742d636f6e7665727465722e7376673f7374796c653d666c61742d737175617265)](https://codeclimate.com/github/jordanbrauer/unit-converter)[![Technical Debt](https://camo.githubusercontent.com/f58eaeb96b9895c29ff793bae6775d324a63fcc549e3468f7f84027965983d30/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636c696d6174652f746563682d646562742f6a6f7264616e6272617565722f756e69742d636f6e7665727465722e7376673f7374796c653d666c61742d737175617265)](https://codeclimate.com/github/jordanbrauer/unit-converter/issues)[![Maintenance](https://camo.githubusercontent.com/3e0af71a1b3b9a736e9b71c8729f614e70dda22f233feea7862b52cdf4a44d5c/68747470733a2f2f696d672e736869656c64732e696f2f6d61696e74656e616e63652f7965732f323032322e7376673f7374796c653d666c61742d737175617265)](https://github.com/jordanbrauer/unit-converter)[![Packagist](https://camo.githubusercontent.com/4e230ea1ade06b2d59e118b542b90e0befd8a99df5c6d0f8b091c6fb0558db1e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a6f7264616e6272617565722f756e69742d636f6e7665727465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jordanbrauer/unit-converter)

Convert all kinds of standard units of measurement from one to another with this highly customizable, easy to use, lightweight PHP component.

**Table of Contents:**

1. [About the Component](#1-about-the-component)
2. [Installing the Component](#2-installing-the-component)
3. [Basic Usage](#3-basic-usage)
4. [Documentation](#4-documentation)

1. About the Component
----------------------

[](#1-about-the-component)

This unit converter component aims to be modern and follow best practices. It also aims to be fully SI compliant (eventually...).

It supports the following types of measurement by default (support for more measurement types are on the roadmap).

- Area
- Data Transfer Rates *Coming Soon!*
- Digital Storage ***New!***
- Energy (Power)
- Frequency
- Fuel Economy
- Length
- Mass (Weight)
- Plane Angle (Rotation)
- Pressure
- Speed
- Temperature
- Time
- Volume

You also have the ability to override &amp; customize the default units, as well as [add your own](https://github.com/jordanbrauer/unit-converter/wiki/Unit-Customization-&-Extension#adding-your-own-custom-units)!

2. Installing the Component
---------------------------

[](#2-installing-the-component)

The best way to install the component is with Composer. For other supported methods, [see the wiki](https://github.com/jordanbrauer/unit-converter/wiki/Installing-the-Package) artile on installation.

```
$ composer require jordanbrauer/unit-converter

```

3. Basic Usage
--------------

[](#3-basic-usage)

Using the component is very easy, especially if you have used the Symfony or Laravel frameworks before.

### Quick-Start

[](#quick-start)

If you'd like to skip the minutiae of this component's setup and get right down to business, you can get started by constructing a pre-configured converter via static constructors or the builder object, like so,

###### Static Constructors

[](#static-constructors)

```
use UnitConverter\UnitConverter;

$converter = UnitConverter::default(); # simple calculator
$converter = UnitConverter::binary(); # binary calculator (BC math)
```

###### Builder

[](#builder)

```
use UnitConverter\UnitConverter;

$converter = UnitConverter::createBuilder()
    ->addSimpleCalculator()
    ->addDefaultRegistry()
    ->build();
```

and use it like this,

```
$converter->convert(1)->from("in")->to("cm"); # (float) 2.54
```

and you're done! For a more in-depth setup guide, [**check the wiki**](https://github.com/jordanbrauer/unit-converter/wiki).

### Usage Examples

[](#usage-examples)

Here are where some usage examples of something that may fit more along the lines of *"real-life"*, are found. Keep in mind that the code examples in each use-case, while working &amp; valid, do contain **some** pseudo-code in them for demonstration purposes.

#### The Traffic Camera

[](#the-traffic-camera)

In this example, pretend we have a traffic camera that only captures speeds in Imperial measurement of *miles per hour*. The traffic camera records each passing car's speed to determine if they were speeding &amp; if so, snap a photo of their license plate as proof to serve a ticket. In this case, the camera caught a speed of `59` *miles per hour*.

Here we construct a new unit &amp; give it a value representing how many of the unit exists,

```
$capturedSpeed = new MilePerHour(59);
```

Next, a conversion of units needs to take place, because this traffic camera model is being used in a country that uses the metric system.

As you can see in this example, we are leveraging the power of typehints to ensure we only receive units of the desired measurement. Inside of the closure, we are using one of the unit's most convenient &amp; powerful methods: `as()`. It allows us to convert units without the direct use of the `UnitConverter` &amp; `UnitRegistry` objects – giving the benefit of even cleaner code &amp; type safety.

```
$isOverSpeedLimit = function (SpeedUnit $speed) {
    return $speed->as(new KilometrePerHour) > 50;
};

if ($isOverSpeedLimit($capturedSpeed)) { # (bool) true
    TrafficCamera::snapPhoto();
}
```

#### Conversion Results as Words

[](#conversion-results-as-words)

Sometimes you might need localization support for values. This component makes that a breeze by making using the `intl` extension. Simply opt for using the `spellout` method in lieu of `to`. You may also provide an optional locale as the second parameter to translate.

```
$converter->convert(1)->from('in')->spellout('cm');       # (string) two point five four
$converter->convert(1)->from('in')->spellout('cm', 'fr'); # (string) deux virgule cinq quatre
```

4. Documentation
----------------

[](#4-documentation)

There are two kinds of in-depth documentation for this project: user &amp; API documentation. Use whichever one you need to help answer your questions!

### User Documentation

[](#user-documentation)

Setup guides, in-depth examples, tutorials, and explanations on the component for users who are looking to integrate it into their project, as-is.

[User Documentation](https://github.com/jordanbrauer/unit-converter/wiki)

### API Documentation

[](#api-documentation)

If you are looking to extend and hack on this component for your own project, these pages will give you insight into all about how the component works, through the awesome power of dockblocks!

[API Documentation](https://jordanbrauer.github.io/unit-converter/)

###  Health Score

47

—

FairBetter than 94% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity57

Moderate usage in the ecosystem

Community31

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 94.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~111 days

Recently: every ~220 days

Total

20

Last Release

999d ago

PHP version history (4 changes)v0.8.0PHP ^7.1

v0.8.6PHP ^7.1 || ^8.0

v0.8.8PHP ^7.3 || ~8.0.0 || ~8.1.0

0.9.0PHP ^7.3 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/867c1f6d15ff437167c0d7467b16da89095218d52e19716fbf9155497d100615?d=identicon)[jordanbrauer](/maintainers/jordanbrauer)

---

Top Contributors

[![jordanbrauer](https://avatars.githubusercontent.com/u/18744334?v=4)](https://github.com/jordanbrauer "jordanbrauer (504 commits)")[![jmauerhan](https://avatars.githubusercontent.com/u/4204262?v=4)](https://github.com/jmauerhan "jmauerhan (10 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (3 commits)")[![martianoff](https://avatars.githubusercontent.com/u/7222812?v=4)](https://github.com/martianoff "martianoff (2 commits)")[![Progi1984](https://avatars.githubusercontent.com/u/1533248?v=4)](https://github.com/Progi1984 "Progi1984 (2 commits)")[![proualexandre](https://avatars.githubusercontent.com/u/16545653?v=4)](https://github.com/proualexandre "proualexandre (2 commits)")[![MammutAlex](https://avatars.githubusercontent.com/u/10599196?v=4)](https://github.com/MammutAlex "MammutAlex (1 commits)")[![Ocramius](https://avatars.githubusercontent.com/u/154256?v=4)](https://github.com/Ocramius "Ocramius (1 commits)")[![andrejsstepanovs](https://avatars.githubusercontent.com/u/324553?v=4)](https://github.com/andrejsstepanovs "andrejsstepanovs (1 commits)")[![R3l4x3](https://avatars.githubusercontent.com/u/5042379?v=4)](https://github.com/R3l4x3 "R3l4x3 (1 commits)")[![booni3](https://avatars.githubusercontent.com/u/20134485?v=4)](https://github.com/booni3 "booni3 (1 commits)")[![cezam](https://avatars.githubusercontent.com/u/3728163?v=4)](https://github.com/cezam "cezam (1 commits)")[![elliotwms](https://avatars.githubusercontent.com/u/4396779?v=4)](https://github.com/elliotwms "elliotwms (1 commits)")[![Fakhruu](https://avatars.githubusercontent.com/u/1495503?v=4)](https://github.com/Fakhruu "Fakhruu (1 commits)")[![laurent35240](https://avatars.githubusercontent.com/u/473193?v=4)](https://github.com/laurent35240 "laurent35240 (1 commits)")

---

Tags

componentcomposerlibrarymeasurementsooppackagephpphp7registryunit-conversionunit-converter

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/jordanbrauer-unit-converter/health.svg)

```
[![Health](https://phpackages.com/badges/jordanbrauer-unit-converter/health.svg)](https://phpackages.com/packages/jordanbrauer-unit-converter)
```

###  Alternatives

[moltin/laravel-cart

Shopping cart package

27624.9k](/packages/moltin-laravel-cart)[andriichuk/laracash

PHP Laravel Money Package

74108.2k1](/packages/andriichuk-laracash)[tobimori/kirby-dreamform

Kirby DreamForm is an opiniated form builder plugin for Kirby CMS 4+ that makes forms work like magic

578.2k1](/packages/tobimori-kirby-dreamform)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
