PHP code example of illegal / fluent-bcmath

1. Go to this page and download the library: Download illegal/fluent-bcmath library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

illegal / fluent-bcmath example snippets


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

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

use Illegal\FluentBCMath\BCNumber;

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

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

$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

$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