PHPackages                             switchsystems/precision-maths - 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. switchsystems/precision-maths

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

switchsystems/precision-maths
=============================

Wrapper for the BCMath extension for precise basic and advanced math operations

0.3.1(11y ago)012MPL-2.0PHPPHP &gt;=5.4.0

Since Jan 6Pushed 11y ago6 watchersCompare

[ Source](https://github.com/SwitchSystems/PrecisionMaths)[ Packagist](https://packagist.org/packages/switchsystems/precision-maths)[ RSS](/packages/switchsystems-precision-maths/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelogDependencies (1)Versions (5)Used By (0)

Precision Maths
===============

[](#precision-maths)

This module provides various classes for performing precision mathematics using BC MATH internally

See  for more information on the BC Math Extension

Licence
-------

[](#licence)

This library is copyright 2014, 2015 Switch Systems Ltd and is licenced under the [Mozilla Public License 2.0](https://www.mozilla.org/MPL/2.0/).

Number Class
------------

[](#number-class)

The precision number class provides all the basic math operations provides by the BC Math extension

Numbers are immutable and will always return a new object with the value of the operation.

**Example:**

```
$number = new Number('20'); // Instatiates Number object with a value of 20
$result = $number->add('20'); // returns a new instance of Number with a value of 40
echo $result; // prints '40'

```

Number Collection Class
-----------------------

[](#number-collection-class)

The number collection can be instatiated with an array as the first argument. It has various methods for performing basic math operations on the set

- Mean
- Median
- Standard Deviation
- Range

**Example:**

```
$numberCollection = new NumberCollection(['1', '2', '3']);
$mean = $numberCollection->mean(); // returns a new instance of number set to the value of the mean of the set
echo $mean; // prints '2'

```

Tax Utility
-----------

[](#tax-utility)

This utility class can be instatiated to perform basic tax operations. It takes tax rate as the first argument of the constructor

### Methods:

[](#methods)

#### fetchValueOfTaxToBeAdded

[](#fetchvalueoftaxtobeadded)

Returns the value of tax that would be added:

```
$vatUtil = new TaxUtility('20');
$vat = $vatUtil->fetchValueOfTaxToBeAdded('125'); // Returns instance of number set to '25'
echo $vat // prints '25'

```

#### fetchValueOfAddedTax

[](#fetchvalueofaddedtax)

Returns the value of tax that would be added:

```
$vatUtil = new TaxUtility('20');
$vat = $vatUtil->fetchValueOfAddedTax('150'); // Returns instance of number set to '25'
echo $vat // prints '25'

```

#### addTaxTo

[](#addtaxto)

Returns the value of tax that would be added:

```
$vatUtil = new TaxUtility('20');
$priceWithVat = $vatUtil->addTaxTo('125'); // Returns instance of number set to '150'
echo $priceWithVat // prints '150'

```

#### removeTaxFrom

[](#removetaxfrom)

Returns the value of tax that would be added:

```
$vatUtil = new TaxUtility('20');
$priceWithVatRemoved = $vatUtil->removeTaxFrom('150'); // Returns instance of number set to '125'
echo $priceWithVatRemoved // prints '125'

```

Finance Utility
---------------

[](#finance-utility)

Currently only provides one method:

### calculatePayForPeriod

[](#calculatepayforperiod)

```
$financeUtil = new FinanceUtility();
$pay = $financeUtil->calculatePayForPeriod($startDateTimeObject, $endDateTimeObject, '6.50', '30');

```

Decimal DateTime Utility
------------------------

[](#decimal-datetime-utility)

This class has a variety of methods for calculating time in a specified unit for a date range and various convertion methods

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~13 days

Total

3

Last Release

4123d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e7f19b47e122e6ae68ca57ea71a8874e0d5111603fb1e896358844134a89d76b?d=identicon)[switchsystems](/maintainers/switchsystems)

---

Top Contributors

[![exptom](https://avatars.githubusercontent.com/u/4302032?v=4)](https://github.com/exptom "exptom (7 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/switchsystems-precision-maths/health.svg)

```
[![Health](https://phpackages.com/badges/switchsystems-precision-maths/health.svg)](https://phpackages.com/packages/switchsystems-precision-maths)
```

###  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)
