PHPackages                             pbaczek/fraction - 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. pbaczek/fraction

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

pbaczek/fraction
================

Library that handles fractions as nominator/denominator

v1.0.5(1y ago)010MITPHPPHP 8.3.\*CI passing

Since May 8Pushed 2mo ago1 watchersCompare

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

READMEChangelog (7)Dependencies (1)Versions (16)Used By (0)

fraction
========

[](#fraction)

Fraction is a PHP library for doing a fraction operation in a human-like way. Normally when you do mathematical operations in any programming language you get approximations, presented in a decimal form.

Fraction class
--------------

[](#fraction-class)

This class represents human like fraction operations

1. Simple addition

```
use pbaczek\fraction\Fraction;

// 1/2 or 0.5
$fractionHalf = new Fraction(1, 2);

// 3/17 or 0,17647...
$fractionThreeSeventeenth = new Fraction(3, 17);

$additionResult = Fraction::from($fractionHalf);
$additionResult->add($fractionThreeSeventeenth);

// 23/34
echo $additionResult;
// 0.68
echo $additionResult->getRealValue();
```

2. Subtraction

```
use pbaczek\fraction\Fraction;

// -1/2
$negativeHalf = new Fraction(-1, 2);
// 1/2
$positiveHalf = new Fraction(1, 2);

$subtractionResult = Fraction::from($negativeHalf);
$subtractionResult->subtract($positiveHalf);
// -1
echo $subtractionResult;
// -1
echo $subtractionResult->getRealValue();
```

3. Multiplication

```
use pbaczek\fraction\Fraction;

// 2/3
$twoEleventh = new Fraction(2, 11);

$minusThreeSeventeenth = new Fraction(-3, 17);

$multiplicationResult = Fraction::from($twoEleventh);
$multiplicationResult->multiply($minusThreeSeventeenth);

// -6/187
echo $multiplicationResult;
// -0.03
echo $multiplicationResult->getRealValue();
```

4. Division

```
use pbaczek\fraction\Fraction;

// 2
$two = new Fraction(2);

// 1/2
$oneHalf = new Fraction(1, 2);

$divisionResult = Fraction::from($two);
$divisionResult->divide($oneHalf);

// 4
echo $divisionResult;
// 4
echo $divisionResult->getRealValue();
```

MFraction class
---------------

[](#mfraction-class)

This class utilizes [https://en.wikipedia.org/wiki/Big\_M\_method](https://en.wikipedia.org/wiki/Big_M_method)

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance70

Regular maintenance activity

Popularity5

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity75

Established project with proven stability

 Bus Factor1

Top contributor holds 97.9% 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 ~239 days

Recently: every ~5 days

Total

7

Last Release

399d ago

Major Versions

v0.0.1 → v1.0.02025-03-11

PHP version history (2 changes)v0.0.1PHP 7.\*

v1.0.0PHP 8.3.\*

### Community

Maintainers

![](https://www.gravatar.com/avatar/6523c773311d1d4344d56e201c8aa4d69935bb8fb6b29501064973ccf1fcd826?d=identicon)[piotrgolasz](/maintainers/piotrgolasz)

---

Top Contributors

[![piotrbaczek](https://avatars.githubusercontent.com/u/3279928?v=4)](https://github.com/piotrbaczek "piotrbaczek (46 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/pbaczek-fraction/health.svg)

```
[![Health](https://phpackages.com/badges/pbaczek-fraction/health.svg)](https://phpackages.com/packages/pbaczek-fraction)
```

###  Alternatives

[ticketswap/phpstan-error-formatter

A minimalistic error formatter for PHPStan

87578.8k35](/packages/ticketswap-phpstan-error-formatter)[arutil/ar-php

Arabic php utilities from Khaled Al-Sham'aa's library http://ar-php.org/

1735.1k](/packages/arutil-ar-php)

PHPackages © 2026

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