PHP code example of thedevick / precise-money

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

    

thedevick / precise-money example snippets




use TheDevick\PreciseMoney\Calculator\BCMathCalculator;
use TheDevick\PreciseMoney\Money;

$money = new Money('10', new BCMathCalculator(3)); // Start with $10.000, using the BCMathCalculator with scale 3 (The default is using scale 10)
$money = $money->addMoney(new Money('3')); // Add $3.000
$money = $money->add('5.235'); // Add $5.235

return json_encode($money); // Returns {"amount":"18.235"}