Usage
Usage
Start now and enjoy performing calculations! 😃
The package is centered around the concept of BCNumber, an object that contains a numeric value and a scale.
What is the scale?
The scale is an integer that represents the number of digits following the decimal point.
There are two options for utilizing the fluent interface, and both require two arguments: the number and the scale. The number can be any of the following:
a string
an integer
a float
another BCNumber instance
All calculation methods return a new BCNumber instance, allowing for seamless method chaining.
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();
Using the BCNumber class
use Illegal\FluentBCMath\BCNumber;
$num = new BCNumber('1.23', 2); // 1st argument is the number, 2nd argument is the scale
Using the fnum() helper function
$num = fnum('1.23', 2); // 1st argument is the number, 2nd argument is the scale
To view all available methods, please consult the reference section.