1. Go to this page and download the library: Download ph-il/money-bundle 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/ */
ph-il / money-bundle example snippets
use Money\Money;
use Phil\MoneyBundle\Form\Type\MoneyType;
// the money library
$fiveEur = Money::EUR(500);
$tenEur = $fiveEur->add($fiveEur);
list($part1, $part2, $part3) = $tenEur->allocate(array(1, 1, 1));
assert($part1->equals(Money::EUR(334)));
assert($part2->equals(Money::EUR(333)));
assert($part3->equals(Money::EUR(333)));
// a service that stores conversion ratios
$pairManager = $this->get('phil_money.pair_manager');
$usd = $pairManager->convert($tenEur, 'USD');
// a form integration
$formBuilder->add('price', MoneyType::class);
use Money\Money;
$pairManager = $this->get("phil_money.pair_manager");
$pairManager->saveRatio('USD', 1.25); // save in ratio file in CSV
$eur = Money::EUR(100);
$usd = $pairManager->convert($amount, 'USD');
$this->assertEquals(Money::USD(125), $usd);
namespace My\Controller\IndexController;
use Money\Money;
use Money\Currency;
class IndexController extends Controller
{
public function myAction()
{
$moneyFormatter = $this->get('phil_money.formatter.money_formatter');
$price = new Money(123456789, new Currency('EUR'));
\Locale::setDefault('fr_FR');
$formatedPrice = $moneyFormatter->localizedFormatMoney($price);
// 1 234 567,89 €
$formatedPrice = $moneyFormatter->localizedFormatMoney($price, 'en');
// €1,234,567.89
}
}
$pairHistoryManager = $this->get("phil_money.pair_history_manager");
$dt = new \DateTime("2012-07-08 11:14:15.638276");
// returns ratio for at a given date
$ratio = $pairHistoryManager->getRatioAtDate('USD',$dt);
// returns the list of USD ratio (relative to the reference value)
$ratioList = $pairHistoryManager->getRatioHistory('USD',$startDate, $endDate);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.