PHPackages                             chawuciren/bignumber - 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. chawuciren/bignumber

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

chawuciren/bignumber
====================

Using a more modern and concise, object-oriented approach, it is more convenient and intuitive to solve the super large number and floating point precision problems in PHP

1.0.3(6y ago)191803[1 issues](https://github.com/chawuciren/php-bignumber/issues)1MITPHPPHP &gt;=5.3

Since Nov 12Pushed 6y ago1 watchersCompare

[ Source](https://github.com/chawuciren/php-bignumber)[ Packagist](https://packagist.org/packages/chawuciren/bignumber)[ RSS](/packages/chawuciren-bignumber/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (3)DependenciesVersions (7)Used By (1)

### php-bignumber

[](#php-bignumber)

[![release](https://camo.githubusercontent.com/9547c4acc9ba1c21cf9a427f83cf00caf41fbc2bbc71f59911ef11aa2b7f7635/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f72656c656173652d312e302e312d677265656e2e737667)](https://camo.githubusercontent.com/9547c4acc9ba1c21cf9a427f83cf00caf41fbc2bbc71f59911ef11aa2b7f7635/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f72656c656173652d312e302e312d677265656e2e737667) [![php](https://camo.githubusercontent.com/2aab165c98b3e8455f5de3be7f655753884e205278c1a7511aefcc40a7e25057/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d2533453d352e332d677265656e2e737667)](https://camo.githubusercontent.com/2aab165c98b3e8455f5de3be7f655753884e205278c1a7511aefcc40a7e25057/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d2533453d352e332d677265656e2e737667) [![downloads](https://camo.githubusercontent.com/73423cc13bbd5ff50e5364aa96090ad6e6d11d3ef642728169f724a2b0dc373d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646f776e6c6f6164732d332e33356b2d677265656e2e737667)](https://camo.githubusercontent.com/73423cc13bbd5ff50e5364aa96090ad6e6d11d3ef642728169f724a2b0dc373d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646f776e6c6f6164732d332e33356b2d677265656e2e737667)

About
-----

[](#about)

[中文文档](./README_zh.md)

The integer size in PHP is platform-dependent. The maximum size is usually 2 billion, and the maximum size on 64-bit platforms is usually 9E18.

Floating-point Numbers have limited precision and depend on the system, so never trust floating-point Numbers to be accurate to the last bit, and never compare two floating-point Numbers to be equal.

When the business scenario needs to deal with a large range of values or needs to accurately deal with floating point values, arbitrary precision mathematical functions should be used, such as: trading system, e-commerce system, etc.

The current project encapsulates arbitrary precision mathematical functions to make it easier to solve large number and floating point precision problems in PHP.

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

[](#installation)

First please make sure your PHP has been installed and the BC Math extension, if not support, specific installation reference website:

See the way:

```
php -info | grep bcmath

```

If you can see the output

```
bcmath
bcmath.scale => 0 => 0

```

BC Math is available

Start the installation:

#### 1. Way 1: By composer

[](#1-way-1-by-composer)

```
composer require chawuciren/bignumber

```

#### 2. Way 2: Directly download and include

[](#2-way-2-directly-download-and-include)

Download the source code directly, introducing src/bignumber.php

Begin to use
------------

[](#begin-to-use)

Initialization of the incoming numeric string should be used, such as a out of numerical and later returned to the front interface, the type of stored in the database as a `DECIMAL`, should first initialize the value of the `BigNumber` will be removed, and then used in the code `BigNumber` calculated, after the return to use on interface: value () method for numerical output string

#### 1. Way 1: use new statements

[](#1-way-1-use-new-statements)

```
use \chawuciren\BigNumber;

$number = new BigNumber('0.002', 3);

```

#### 2. Way 2: use the static method build

[](#2-way-2-use-the-static-method-build)

```
use \chawuciren\BigNumber;

$number = BigNumber::build('0.002', 3);

```

#### 3. Way 3: assign values using the valueOf method

[](#3-way-3-assign-values-using-the-valueof-method)

```
use \chawuciren\BigNumber;

$number = new BigNumber();
$number->valueOf('0.002', 3);

```

Sample
------

[](#sample)

```
use \chawuciren\BigNumber;

$number = new BigNumber('1.0001', 4);
$number->add('0.0004')->sub('1')->mul('4')->div('5');
var_dump($number->value()); //string(5) "0.0002"

$number2 = new BigNumber('0.0002');
var_dump($number->eq($number2)) //bool true

```

Methods list
------------

[](#methods-list)

#### 1.valueOf

[](#1valueof)

Set a value to the BigNumber instance

##### Parameters:

[](#parameters)

Parameter namesTypeInstructionsnumberString/BigNumberA string or number of type BigNumberscaleIntPrecision of number##### Return value: BigNumber(Current instance)

[](#return-value-bignumbercurrent-instance)

##### Sample:

[](#sample-1)

```
$number = new \chawuciren\BigNumber();
$number->valueOf('0.002', 3);
var_dump($number); //object(chawuciren\BigNumber)

```

#### 2.toString

[](#2tostring)

Returns a value as a string

##### Parameters:

[](#parameters-1)

No parameters

##### Reture value: String(Current value)

[](#reture-value-stringcurrent-value)

##### Sample:

[](#sample-2)

```
$number = new \chawuciren\BigNumber('0.002', 3);
$str = $number->toString();
var_dump($str); //string(5) "0.002"

```

#### 3.value

[](#3value)

Returns a value of type string, currently an alias of the toString method

##### Sample:

[](#sample-3)

```
$number = new \chawuciren\BigNumber('0.002', 3);
$str = $number->value();
var_dump($str); //string(5) "0.002"

```

#### 4.add

[](#4add)

Adds the current value plus the number value passed in

##### Parameters:

[](#parameters-2)

Parameter namesTypeInstructionsnumberString/BigNumberThe value used to add##### Reture value: BigNumber(Current instance)

[](#reture-value-bignumbercurrent-instance)

##### Sample:

[](#sample-4)

```
$number = new \chawuciren\BigNumber('0.002', 3);
$number->add('0.003');
var_dump($number->value()); //string(5) "0.005"

```

#### 5.sub

[](#5sub)

Subtracts the current value from the number value passed in

##### Parameters:

[](#parameters-3)

Parameter namesTypeInstructionsnumberString/BigNumberThe value used to subtract##### Reture value: BigNumber(Current instance)

[](#reture-value-bignumbercurrent-instance-1)

##### Sample:

[](#sample-5)

```
$number = new \chawuciren\BigNumber('0.002', 3);
$number->sub('0.001');
var_dump($number->value()); //string(5) "0.001"

```

#### 6.mul

[](#6mul)

Multiply the current value by the number value passed in

##### Parameters:

[](#parameters-4)

Parameter namesTypeInstructionsnumberString/BigNumberThe number used to multiply##### Reture value: BigNumber(Current instance)

[](#reture-value-bignumbercurrent-instance-2)

##### Sample:

[](#sample-6)

```
$number = new \chawuciren\BigNumber('0.002', 3);
$number->sub('0.001');
var_dump($number->value()); //string(5) "0.001"

```

#### 7.div

[](#7div)

Divide the current value by the number value passed in

##### Parameters:

[](#parameters-5)

Parameter namesTypeInstructionsnumberString/BigNumberDivide the current value by the number value passed in##### Reture value: BigNumber(Current instance)

[](#reture-value-bignumbercurrent-instance-3)

##### Sample:

[](#sample-7)

```
$number = new \chawuciren\BigNumber('0.002', 3);
$number->div('2');
var_dump($number->value()); //string(5) "0.001"

```

#### 8.mod

[](#8mod)

Modulates the current value with the number value passed in

##### Parameters:

[](#parameters-6)

Parameter namesTypeInstructionsnumberString/BigNumberThe value used to take a modulus##### Reture value: BigNumber(Current instance)

[](#reture-value-bignumbercurrent-instance-4)

##### Sample:

[](#sample-8)

```
$number = new \chawuciren\BigNumber('108');
$number->mod('10');
var_dump($number->value()); //string(1) "8"

```

#### 9.pow

[](#9pow)

Take the current value to the number power

##### Parameters:

[](#parameters-7)

Parameter namesTypeInstructionsnumberString/BigNumberThe number of powers##### Reture value: BigNumber(Current instance)

[](#reture-value-bignumbercurrent-instance-5)

##### Sample:

[](#sample-9)

```
$number = new \chawuciren\BigNumber('2');
$number->pow('2');
var_dump($number->value()); //string(1) "4"

```

#### 10.sqrt

[](#10sqrt)

Take the square root of the current value

##### Parameters:

[](#parameters-8)

No parameters

##### Reture value: BigNumber(Current instance)

[](#reture-value-bignumbercurrent-instance-6)

##### Sample:

[](#sample-10)

```
$number = new \chawuciren\BigNumber('16');
$number->sqrt();
var_dump($number->value()); //string(1) "4"

```

#### 11.eq

[](#11eq)

Determine whether the current value equals the value of number

##### Parameters:

[](#parameters-9)

Parameter namesTypeInstructionsnumberString/BigNumberThe rvalue participating in the judgment##### Reture value: Bool (True: equal; False: no equal)

[](#reture-value-bool-true-equal-false-no-equal)

##### Sample:

[](#sample-11)

```
$number = new \chawuciren\BigNumber('0.00000000000000000001', 20);
$number2 = new \chawuciren\BigNumber('0.00000000000000000001', 20);
var_dump($number->eq($number2)); //bool(true)

```

#### 12.gt

[](#12gt)

Determine whether the current value is greater than the number value

##### Parameters:

[](#parameters-10)

Parameter namesTypeInstructionsnumberString/BigNumberThe rvalue participating in the judgment##### Reture value: Bool (True: greater than; False: no more than)

[](#reture-value-bool-true-greater-than-false-no-more-than)

##### Sample:

[](#sample-12)

```
$number = new \chawuciren\BigNumber('0.00000000000000000002', 20);
$number2 = new \chawuciren\BigNumber('0.00000000000000000001', 20);
var_dump($number->gt($number2)); //bool(true)

```

#### 13.egt

[](#13egt)

Determine whether the current value is greater than or equal to the number value

##### Parameters:

[](#parameters-11)

Parameter namesTypeInstructionsnumberString/BigNumberThe rvalue participating in the judgment##### Reture value: Bool (True: greater than or equal to; False: not greater than and not equal to)

[](#reture-value-bool-true-greater-than-or-equal-to-false-not-greater-than-and-not-equal-to)

##### Sample:

[](#sample-13)

```
$number = new \chawuciren\BigNumber('0.00000000000000000002', 20);
$number2 = new \chawuciren\BigNumber('0.00000000000000000001', 20);
var_dump($number->egt($number2)); //bool(true)

```

#### 14.lt

[](#14lt)

Determine whether the current value is less than the number value

##### Parameters:

[](#parameters-12)

Parameter namesTypeInstructionsnumberString/BigNumberThe rvalue participating in the judgment##### Reture value: Bool (True: less than; False: no less than)

[](#reture-value-bool-true-less-than-false-no-less-than)

##### Sample:

[](#sample-14)

```
$number = new \chawuciren\BigNumber('0.00000000000000000002', 20);
$number2 = new \chawuciren\BigNumber('0.00000000000000000001', 20);
var_dump($number->lt($number2)); //bool(false)

```

#### 15.elt

[](#15elt)

Determine whether the current value is less than or equal to the value of number

##### Parameters:

[](#parameters-13)

Parameter namesTypeInstructionsnumberString/BigNumberThe rvalue participating in the judgment##### Reture value: Bool (True: less than or equal to; False: not less than and not equal to)

[](#reture-value-bool-true-less-than-or-equal-to-false-not-less-than-and-not-equal-to)

##### Sample:

[](#sample-15)

```
$number = new \chawuciren\BigNumber('0.00000000000000000002', 20);
$number2 = new \chawuciren\BigNumber('0.00000000000000000001', 20);
var_dump($number->lt($number2)); //bool(false)

```

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity61

Established project with proven stability

 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 ~45 days

Recently: every ~57 days

Total

6

Last Release

2552d ago

Major Versions

0.1.2 → 1.0.12019-06-28

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4428282?v=4)[查无此人](/maintainers/chawuciren)[@chawuciren](https://github.com/chawuciren)

---

Top Contributors

[![chawuciren](https://avatars.githubusercontent.com/u/4428282?v=4)](https://github.com/chawuciren "chawuciren (29 commits)")

---

Tags

bignumberdecimalfloatnumberphp

### Embed Badge

![Health badge](/badges/chawuciren-bignumber/health.svg)

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

###  Alternatives

[blair2004/nexopos

The Free Modern Point Of Sale System build with Laravel, TailwindCSS and Vue.js.

1.2k2.4k](/packages/blair2004-nexopos)[questocat/laravel-referral

A Referral System With Laravel

13891.3k](/packages/questocat-laravel-referral)[beyondcode/tinkerwell-helper

Open Tinkerwell from your Laravel project.

5999.1k](/packages/beyondcode-tinkerwell-helper)[alekseon/widget-forms

N/A

5041.8k1](/packages/alekseon-widget-forms)[noherczeg/breadcrumb

A simple breadcrumb generator library.

6618.7k1](/packages/noherczeg-breadcrumb)[kevinlebrun/password.php

Helpers for password generation and validation

17145.0k1](/packages/kevinlebrun-passwordphp)

PHPackages © 2026

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