1. Go to this page and download the library: Download matmar10/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/ */
matmar10 / money-bundle example snippets
$eur = new Currency('EUR', 2, 2);
$euros = new Money($eur);
$euros->setAmountFloat(1.99);
// must use a valid iso4217 currency code
// with the exception of BTC for Bitcoin, as specified in the override configuration
$usd = new Currency('USD', 5, 2);
$usdAmount1 = new Money($usd);
$usdAmount1->setAmountFloat(1.2345);
$usdAmount2 = new Money($usd);
$usdAmount2->setAmountFloat(1.2345);
$usdAmount1->isEqual($usdAmount2); // true
$resultAmount1 = $usdAmount1->add($usdAmount2);
echo $resultAmount1->getAmountDisplay(); // 2.47
$resultAmount2 = $usdAmount1->subtract($usdAmount2);
echo $resultAmount2->getAmountFloat(); // 0
$resultAmount3 = $usdAmount1->multiply(3);
echo $resultAmount3->getAmountFloat(); // 3.7035
echo $resultAmount3->getAmountDisplay(); // 3.70
$resultAmount4 = $usdAmount1->divide(2);
echo $resultAmount3->getAmountFloat(); // 0.61725
echo $resultAmount3->getAmountDisplay(); // 0.62
$eurAmount = new Money(new Currency('EUR', 2, 2));
$eurAmount->setAmountFloat(10);
// split the 10 euros into three equal parts using euro cents as the smallest unit
$shares = $eurAmount->allocate(array(1, 1, 1), 2);
$shares[0]->getAmountFloat(); // 3.34
$shares[1]->getAmountFloat(); // 3.33
$shares[2]->getAmountFloat(); // 3.33
// inside an entity file, such as src/Bundle/AcmeBundle/Entity/Purchase.php
namespace Acme\Bundle\AcmeBundle\Entity;
use Lmh\Bundle\MoneyBundle\Validator\Constraints as Assert;
class Purchase
{
/**
* @Assert\CurrencyCode()
*/
public $currency;
}
use Acme\Bundle\AcmeBundle;
use Symfony\Component\Validator\Validation;
$validator = Validation::createValidatorBuilder()
->enableAnnotationMapping()
->getValidator();
$purchase = new Purchase()
$purchase->currency = 'invalid-this-is-not-a-code';
$violations = $validator->validate($purchase);
namespace foo\bar;
use Doctrine\ORM\Mapping as ORM;
class Invoice {
/**
* @var \Matmar10\Money\Entity\Money
* @ORM\Embedded(columnPrefix="price_", class="Matmar10\Money\Entity\Money")
*/
private $price;
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.