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

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

phospr/fraction
===============

A composer-installable fractions library

v1.2.1(9y ago)34327.5k↓11.5%11[3 PRs](https://github.com/phospr/fraction/pulls)2MITPHPPHP &gt;=5.3.0

Since Nov 5Pushed 2y ago2 watchersCompare

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

READMEChangelog (2)Dependencies (1)Versions (13)Used By (2)

Phospr Fraction
===============

[](#phospr-fraction)

[![Build Status](https://camo.githubusercontent.com/61f55bd1a9ef91c0a07acaaa841cd296ef82265c07e8550f40193027188b38ad/68747470733a2f2f7472617669732d63692e6f72672f70686f7370722f6672616374696f6e2e737667)](https://travis-ci.org/phospr/fraction)[![Coverage Status](https://camo.githubusercontent.com/5ef36ca0515726cdf8db7f3f4f694e8b2dbf5602f6bf5d5c432df0551af12d80/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f70686f7370722f6672616374696f6e2f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/phospr/fraction?branch=master)

Composer-installable fractions for PHP

Usage
-----

[](#usage)

```
use Phospr\Fraction;
```

#### Simple Fractions

[](#simple-fractions)

```
echo new Fraction(1, 2); // 1/2
echo new Fraction(5, 2); // 2 1/2
```

#### Create Fraction from string

[](#create-fraction-from-string)

```
echo Fraction::fromString('1 2/3'); // 1 2/3
echo Fraction::fromString('28/4'); // 7
```

#### Create Fraction from float

[](#create-fraction-from-float)

```
echo Fraction::fromFloat(1.5); // 1 1/2
```

#### Auto-simplified

[](#auto-simplified)

Fractions are simplified at construction

```
echo new Fraction(4, 6); // 2/3
```

#### Addition

[](#addition)

```
$fraction = new Fraction(2, 7);
echo $fraction->add(new Fraction(3, 11)); // 43/77
```

#### Subtraction

[](#subtraction)

```
$fraction = new Fraction(6);
echo $fraction->subtract(new Fraction(2, 3)); // 5 1/3
```

#### Multiplication

[](#multiplication)

```
$fraction = new Fraction(1, 2);
echo $fraction->multiply(new Fraction(1, 2)); // 1/4
```

#### Division

[](#division)

```
$fraction = new Fraction(6, 13);
echo $fraction->divide(new Fraction(2, 7)); // 1 8/13
```

#### To Float

[](#to-float)

```
$fraction = new Fraction(1, 8);
$fraction->toFloat(); // 0.125
```

#### Is Integer?

[](#is-integer)

Check whether a fraction is in fact a whole number.

```
$fraction = new Fraction(1, 8);
$fraction->isInteger(); // false

$fraction = new Fraction(16, 8);
$fraction->isInteger(); // true
```

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

[](#installation)

Add package to your composer.json file

```
{
    "require": {
        "phospr/fraction": "dev-master"
    }
}
```

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity47

Moderate usage in the ecosystem

Community21

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 61.8% 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 ~128 days

Recently: every ~272 days

Total

10

Last Release

2690d ago

Major Versions

v0.5.0 → v1.0.02016-01-10

### Community

Maintainers

![](https://www.gravatar.com/avatar/2f7a54fbc3ac6dfedf6fb7d34386c2d95aa9dae6c1ac706134b849a8ce5355e2?d=identicon)[tomhv](/maintainers/tomhv)

---

Top Contributors

[![tomhv](https://avatars.githubusercontent.com/u/301805?v=4)](https://github.com/tomhv "tomhv (42 commits)")[![imctomhv](https://avatars.githubusercontent.com/u/24391197?v=4)](https://github.com/imctomhv "imctomhv (20 commits)")[![xstat](https://avatars.githubusercontent.com/u/945507?v=4)](https://github.com/xstat "xstat (4 commits)")[![cmtatro](https://avatars.githubusercontent.com/u/438305?v=4)](https://github.com/cmtatro "cmtatro (1 commits)")[![imcctatro](https://avatars.githubusercontent.com/u/24417655?v=4)](https://github.com/imcctatro "imcctatro (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[slack-php/slack-block-kit

OOP interface for writing Slack Block Kit messages and modals

55754.2k6](/packages/slack-php-slack-block-kit)[symfony/ux-map

Easily embed interactive maps in your Symfony application

18178.5k4](/packages/symfony-ux-map)

PHPackages © 2026

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