PHP code example of tiny-blocks / money

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

    

tiny-blocks / money example snippets


Money::from(value: 10, currency: 'BRL');
Money::from(value: '10', currency: Currency::USD);
Money::from(value: BigDecimal::from(value: '10'), currency: Currency::USD);

$augend = Money::from(value: '100', currency: 'BRL');
$addend = Money::from(value: '1.50', currency: Currency::BRL);

$result = $augend->add(addend: $addend);

$result->amount->toString(); # 101.50

$minuend = Money::from(value: '10.50', currency: 'EUR');
$subtrahend = Money::from(value: '0.50', currency: Currency::EUR);

$result = $minuend->subtract(subtrahend: $subtrahend);

$result->amount->toString(); # 10.00

$multiplicand = Money::from(value: '5', currency: 'GBP');
$multiplier = Money::from(value: '3.12', currency: Currency::GBP);

$result = $multiplicand->multiply(multiplier: $multiplier);

$result->amount->toString(); # 15.60

$dividend = Money::from(value: '8.99', currency: 'CHF');
$divisor = Money::from(value: '5', currency: Currency::CHF);

$result = $dividend->divide(divisor: $divisor);

$result->amount->toString(); # 1.79