PHPackages                             illegal/fluent-bcmath - 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. illegal/fluent-bcmath

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

illegal/fluent-bcmath
=====================

Fluent BCMath is a PHP package designed to simplify the usage of PHP's bcmath functions in a more fluid and intuitive way. With its expressive syntax and Laravel compatibility, it aims to improve the developer experience while working with arbitrary precision arithmetic operations.

v1.0.1(3y ago)27031MITPHPPHP &gt;=8.0

Since Apr 10Pushed 2y ago1 watchersCompare

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

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

fluent-bcmath
=============

[](#fluent-bcmath)

Fluent BcMath is a fluent interface for the PHP BcMath extension.

It helps you to write more readable code, while maintaining the performance of the BcMath extension.

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

[](#installation)

Install the package via composer:

```
composer require "illegal/fluent-bcmath"
```

Usage
-----

[](#usage)

You have two options to use the fluent interface.

In both cases, there are two arguments: the number and the scale. The number can be:

- a string
- an integer
- a float
- another `BCNumber` instance

The scale is an integer, which represents the number of digits after the decimal point.

All methods return a new `BCNumber` instance, so you can chain them.

For example:

```
use Illegal\FluentBCMath\BCNumber;
$num = new BCNumber('1.23', 2);

$num->add(2)->sub(2)->mul(2)->div(2)->mod(3)->pow(2)->sqrt();
```

### 1. Use the `BCNumber` class

[](#1-use-the-bcnumber-class)

```
use Illegal\FluentBCMath\BCNumber;

$num = new BCNumber('1.23', 2); // 1st argument is the number, 2nd argument is the scale
```

### 2. Use the `fnum()` helper function

[](#2-use-the-fnum-helper-function)

```
$num = fnum('1.23', 2); // 1st argument is the number, 2nd argument is the scale
```

Available methods
-----------------

[](#available-methods)

```
$num = fnum(10, 2);

$num->add(2); // 12.00
$num->sub(2); // 8.00
$num->mul(2); // 20.00
$num->div(2); // 5.00
$num->mod(3); // 1.00
$num->pow(2); // 100.00
$num->sqrt(); // 3.16

$num->equals(10); // true
$num->greaterThan(5); // true
$num->greaterThanOrEqual(10); // true
$num->lessThan(15); // true
$num->lessThanOrEqual(10); // true
$num->isZero(); // false
$num->isPositive(); // true
$num->isNegative(); // false
$num->isEven(); // true
$num->isOdd(); // false
$num->abs(); // 10.00
$num->negate(); // -10.00
$num->min(5); // 5.00
$num->max(15); // 15.00
$num->clamp(5, 15); // 10.00
```

If methods
----------

[](#if-methods)

Each operation has an `if` method, which returns the result of the operation, if the condition is true.

```
$num = fnum(10, 2);

$num->addIf(2, false); // 10.00
$num->subIf(2, false); // 10.00
$num->mulIf(2, false); // 10.00
$num->divIf(2, false); // 10.00
$num->modIf(3, false); // 10.00
$num->powIf(2, false); // 10.00
$num->sqrtIf(false); // 10.00
```

Testing
=======

[](#testing)

```
./vendor/bin/pest
```

License
=======

[](#license)

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

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 91.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 ~0 days

Total

2

Last Release

1133d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9d45226dc1c994059bfb274dc3a8a69a45154cdab95c17b18e7fdb804c31202c?d=identicon)[illegalvuppi](/maintainers/illegalvuppi)

---

Top Contributors

[![nahime0](https://avatars.githubusercontent.com/u/436702?v=4)](https://github.com/nahime0 "nahime0 (22 commits)")[![mirchaemanuel](https://avatars.githubusercontent.com/u/1971953?v=4)](https://github.com/mirchaemanuel "mirchaemanuel (2 commits)")

---

Tags

bcmathlaravelmathphpphp-libraryphplaravelmathArbitrary-precisionfluentchainablebcmath

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/illegal-fluent-bcmath/health.svg)

```
[![Health](https://phpackages.com/badges/illegal-fluent-bcmath/health.svg)](https://phpackages.com/packages/illegal-fluent-bcmath)
```

###  Alternatives

[krowinski/bcmath-extended

Extends php BCMath lib for missing functions like floor, ceil, round, abs, min, max, rand for big numbers. Also wraps existing BCMath functions. (more http://php.net/manual/en/book.bc.php) Supports scientific notations

791.0M19](/packages/krowinski-bcmath-extended)[amranidev/laracombee

Recommendation system for laravel

11636.7k1](/packages/amranidev-laracombee)[wujunze/money-wrapper

MoneyPHP Wrapper

113.8k](/packages/wujunze-money-wrapper)

PHPackages © 2026

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