PHP code example of fortis / moneyobject

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

    

fortis / moneyobject example snippets

 php
print (36 - 35.99) === 0.01 ? '✅ equals' : 'not equals 😈';
 php
$money->getCurrency()->getCode(); // USD
 php
$money->getAmount()->toFloat();   // 100.20
 php
$money->multiply(2)
      ->getAmount()->toFloat(); // 200.40
 php
$money->divide(Money::USD(2))
      ->getAmount()->toFloat(); // 50.10
 php
$money->plus(Money::USD(2.5))
      ->getAmount()->toFloat(); // 102.70
 php
$money->minus(Money::USD(0.5))
      ->getAmount()->toFloat(); // 99.70
 php
Money::USD(36)->minus(Money::USD(35.99))
              ->getAmount()->toFloat(); // 0.01
 php
Money::USD(36)->minus(35.99)
              ->getAmount()->toFloat(); // 0.01
 php
$swap = (new SwapBuilder())
    ->add('fixer')
    ->build();
$converter = new Converter($swap);
$usd50 = Money::USD(50);
$result = $converter->convert($usd50, Currency::EUR());