PHP code example of trademinator / bcmath

1. Go to this page and download the library: Download trademinator/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/ */

    

trademinator / bcmath example snippets


use function Trademinator\BcMath\bcabs;
use function Trademinator\BcMath\bcconv;
use function Trademinator\BcMath\bcdec;
use function Trademinator\BcMath\bclog10;
use function Trademinator\BcMath\bcmax;
use function Trademinator\BcMath\bcmin;
use function Trademinator\BcMath\bcpow10;
use function Trademinator\BcMath\bcstddev;

bcdec(['100', '42']);                    // 0
bcdec(['100.10']);                       // 2
bcdec(['100.1000']);                     // 4
bcdec(['100.1000'], trimTrailingZeros: true); // 1

bcconv('1.23456789123456789e-7');
// 0.000000123456789123456789

use Trademinator\BcMath\PrecisionContext;
use Trademinator\BcMath\PrecisionPolicy;
use function Trademinator\BcMath\bcstddev;

$policy = new PrecisionPolicy(
    minimumScale: 16,
    guardDigits: 4,
    maximumScale: 32,
    trimTrailingZeros: true,
);

$precision = PrecisionContext::forPrices($prices, $policy);

$stddev = bcstddev($prices, sample: false, scale: $precision->scale);

bcstddev(['2', '4', '4', '4', '5', '5', '7', '9'], scale: 16);
// 2.0000000000000000

bclog10('2', 16);
// 0.3010299956639811