Download the PHP package chawuciren/bignumber without Composer

On this page you can find all versions of the php package chawuciren/bignumber. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package bignumber

php-bignumber

release php downloads

About

中文文档

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

First please make sure your PHP has been installed and the BC Math extension, if not support, specific installation reference website: http://php.net/manual/en/bc.installation.php

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

composer require chawuciren/bignumber

2. Way 2: Directly download and include

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



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

use \chawuciren\BigNumber;

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

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

use \chawuciren\BigNumber;

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



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

1.valueOf

Set a value to the BigNumber instance

Parameters:
Parameter names Type Instructions
number String/BigNumber A string or number of type BigNumber
scale Int Precision of number
Return value: BigNumber(Current instance)
Sample:
$number = new \chawuciren\BigNumber();
$number->valueOf('0.002', 3);
var_dump($number); //object(chawuciren\BigNumber)


2.toString

Returns a value as a string

Parameters:

No parameters

Reture value: String(Current value)
Sample:
$number = new \chawuciren\BigNumber('0.002', 3);
$str = $number->toString();
var_dump($str); //string(5) "0.002"

3.value

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

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


4.add

Adds the current value plus the number value passed in

Parameters:
Parameter names Type Instructions
number String/BigNumber The value used to add
Reture value: BigNumber(Current instance)
Sample:
$number = new \chawuciren\BigNumber('0.002', 3);
$number->add('0.003');
var_dump($number->value()); //string(5) "0.005"


5.sub

Subtracts the current value from the number value passed in

Parameters:
Parameter names Type Instructions
number String/BigNumber The value used to subtract
Reture value: BigNumber(Current instance)
Sample:
$number = new \chawuciren\BigNumber('0.002', 3);
$number->sub('0.001');
var_dump($number->value()); //string(5) "0.001"


6.mul

Multiply the current value by the number value passed in

Parameters:
Parameter names Type Instructions
number String/BigNumber The number used to multiply
Reture value: BigNumber(Current instance)
Sample:
$number = new \chawuciren\BigNumber('0.002', 3);
$number->sub('0.001');
var_dump($number->value()); //string(5) "0.001"


7.div

Divide the current value by the number value passed in

Parameters:
Parameter names Type Instructions
number String/BigNumber Divide the current value by the number value passed in
Reture value: BigNumber(Current instance)
Sample:
$number = new \chawuciren\BigNumber('0.002', 3);
$number->div('2');
var_dump($number->value()); //string(5) "0.001"


8.mod

Modulates the current value with the number value passed in

Parameters:
Parameter names Type Instructions
number String/BigNumber The value used to take a modulus
Reture value: BigNumber(Current instance)
Sample:
$number = new \chawuciren\BigNumber('108');
$number->mod('10');
var_dump($number->value()); //string(1) "8"


9.pow

Take the current value to the number power

Parameters:
Parameter names Type Instructions
number String/BigNumber The number of powers
Reture value: BigNumber(Current instance)
Sample:
$number = new \chawuciren\BigNumber('2');
$number->pow('2');
var_dump($number->value()); //string(1) "4"


10.sqrt

Take the square root of the current value

Parameters:

No parameters

Reture value: BigNumber(Current instance)
Sample:
$number = new \chawuciren\BigNumber('16');
$number->sqrt();
var_dump($number->value()); //string(1) "4"


11.eq

Determine whether the current value equals the value of number

Parameters:
Parameter names Type Instructions
number String/BigNumber The rvalue participating in the judgment
Reture value: Bool (True: equal; False: no equal)
Sample:
$number = new \chawuciren\BigNumber('0.00000000000000000001', 20);
$number2 = new \chawuciren\BigNumber('0.00000000000000000001', 20);
var_dump($number->eq($number2)); //bool(true)


12.gt

Determine whether the current value is greater than the number value

Parameters:
Parameter names Type Instructions
number String/BigNumber The rvalue participating in the judgment
Reture value: Bool (True: greater than; False: no more than)
Sample:
$number = new \chawuciren\BigNumber('0.00000000000000000002', 20);
$number2 = new \chawuciren\BigNumber('0.00000000000000000001', 20);
var_dump($number->gt($number2)); //bool(true)


13.egt

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

Parameters:
Parameter names Type Instructions
number String/BigNumber The rvalue participating in the judgment
Reture value: Bool (True: greater than or equal to; False: not greater than and not equal to)
Sample:
$number = new \chawuciren\BigNumber('0.00000000000000000002', 20);
$number2 = new \chawuciren\BigNumber('0.00000000000000000001', 20);
var_dump($number->egt($number2)); //bool(true)


14.lt

Determine whether the current value is less than the number value

Parameters:
Parameter names Type Instructions
number String/BigNumber The rvalue participating in the judgment
Reture value: Bool (True: less than; False: no less than)
Sample:
$number = new \chawuciren\BigNumber('0.00000000000000000002', 20);
$number2 = new \chawuciren\BigNumber('0.00000000000000000001', 20);
var_dump($number->lt($number2)); //bool(false)


15.elt

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

Parameters:
Parameter names Type Instructions
number String/BigNumber The rvalue participating in the judgment
Reture value: Bool (True: less than or equal to; False: not less than and not equal to)
Sample:
$number = new \chawuciren\BigNumber('0.00000000000000000002', 20);
$number2 = new \chawuciren\BigNumber('0.00000000000000000001', 20);
var_dump($number->lt($number2)); //bool(false)



All versions of bignumber with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package chawuciren/bignumber contains the following files

Loading the files please wait ....