PHP code example of mathematicator-core / numbers

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

    

mathematicator-core / numbers example snippets


use Brick\Math\RoundingMode;
use Mathematicator\Numbers\SmartNumber;

$smartNumber = SmartNumber::of('80.500');
echo $smartNumber->toBigDecimal(); // 80.500
echo $smartNumber->toFraction()->getNumerator(); // 161
echo $smartNumber->toFraction()->getDenominator(); // 2
echo Calculation::of($smartNumber)->multipliedBy(-4); // -322.000
echo Calculation::of($smartNumber)->multipliedBy(-4)->abs()->getResult()->toInt(); // 322
echo $smartNumber->toBigDecimal()->toScale(0, RoundingMode::HALF_UP); // 81

$smartNumber2 = SmartNumber::of('161/2');
echo $smartNumber2->toHumanString(); // 161/2
echo $smartNumber2->toHumanString()->plus(5)->equals('90.5'); // 161/2+10=90.5
echo $smartNumber2->toLatex(); // \frac{161}{2}
echo $smartNumber2->toBigDecimal();  // 80.5

$result = 0.1 + 0.2;
echo $result; // output: 0.3

echo ($result == 0.3) ? 'true' : 'false'; // output: false