PHPackages                             jacobfitzp/weight-conversions - 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. jacobfitzp/weight-conversions

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

jacobfitzp/weight-conversions
=============================

This is my package weight-conversions

1.1.0(3y ago)143[2 PRs](https://github.com/JacobFitzp/weight-conversions/pulls)MITPHPPHP ^8.1

Since Apr 14Pushed 2y ago1 watchersCompare

[ Source](https://github.com/JacobFitzp/weight-conversions)[ Packagist](https://packagist.org/packages/jacobfitzp/weight-conversions)[ Docs](https://github.com/jacobfitzp/weight-conversions)[ GitHub Sponsors](https://github.com/JacobFitzp)[ RSS](/packages/jacobfitzp-weight-conversions/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (3)Versions (5)Used By (0)

PHP Weight Conversions
======================

[](#php-weight-conversions)

[![Latest Version on Packagist](https://camo.githubusercontent.com/d12bd425de1d2747c2d4a8d8e49c037a9994033d5067daa0ba31536395763155/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a61636f626669747a702f7765696768742d636f6e76657273696f6e732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jacobfitzp/weight-conversions)[![Tests](https://camo.githubusercontent.com/7309bb61a708be2072d274dec1b42c99d983b23651cd7ed0ddc6fbd721b30337/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6a61636f626669747a702f7765696768742d636f6e76657273696f6e732f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/jacobfitzp/weight-conversions/actions/workflows/run-tests.yml)[![Total Downloads](https://camo.githubusercontent.com/18327ad6f455477bbdd8208a30d11c9c8a8b2dcca2ba1e61ca998f1d2685c698/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a61636f626669747a702f7765696768742d636f6e76657273696f6e732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jacobfitzp/weight-conversions)

Simple PHP package to convert between different units of weight measurement.

Supports gram, kilogram, milligram, ounce, pound, stone and ton... and can easily be extended to add additional units.

```
echo (new Pound(27.8))
    ->to(Kilogram::class)
    ->round()
    ->formatted()

// 12.6kg
```

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

[](#installation)

You can install the package via composer:

```
composer require jacobfitzp/weight-conversions
```

Usage
-----

[](#usage)

```
// Create a new measurement unit
$kilograms = new Kilogram();

// Set weight amount
// Can also be passed to the constructor
$kilograms->setAmount(5.75);

// Convert to a different unit type
$ounce = $kilograms->to(Ounce::class);

// Get weight amount
$ounce->amount();

// Round the amount
// Defaults to a precision of 1 decimal place
$ounce->round();

// Get a formatted human-readable version of the amount
// For example "2kgG", "12st 5"
$ounce->formatted();
```

### Extending

[](#extending)

You can create your own units of measurement by extending the `AbstractUnit` class:

```
class Hobnobs extends AbstractUnit
{
    public const RELATIVE_TO_KG = 50;

    public function formatted(string $format = '%s hobnobs'): string
    {
        return sprintf($format, $this->amount());
    }
}
```

Let's break down how this works... The main thing to be aware of is the `RELATIVE_TO_KG` constant, this represents the amount of the unit that is relative to 1kg - For exampe, above we are saying that 50 hobnobs = 1kg. This is used as the basis for all conversion calculations.

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Jacob Fitzpatrick](https://github.com/JacobFitzp)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 50% 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 ~1 days

Total

2

Last Release

1119d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/780c761e3f0522b0200da41fd247e494ecfd4c745bb50517b8f15828628fd1b0?d=identicon)[JacobFitzp](/maintainers/JacobFitzp)

---

Top Contributors

[![JacobFitzp](https://avatars.githubusercontent.com/u/34043417?v=4)](https://github.com/JacobFitzp "JacobFitzp (6 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (3 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (3 commits)")

---

Tags

conversionconverterphpweightJacobFitzpweight-conversions

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/jacobfitzp-weight-conversions/health.svg)

```
[![Health](https://phpackages.com/badges/jacobfitzp-weight-conversions/health.svg)](https://phpackages.com/packages/jacobfitzp-weight-conversions)
```

###  Alternatives

[netzmacht/php-leaflet

PHP leaflet definition and javascript generator

1927.2k2](/packages/netzmacht-php-leaflet)

PHPackages © 2026

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