README

This Symfony2 bundle provide a service and a twig extension to convert and display currencies.

Installation

Add the bunde to your composer.json file:

require: {// ..."lexik/currency-bundle": "~2.0"// ...}

As of version 1.2.0, currency_format does not convert the currency anymore, it only formats the given value according to the locale. If you need to convert and format a value, please use currency_convert_format filter.

Then run a composer update:

composer.phar update
# OR
composer.phar update lexik/currency-bundle # to only update the bundle

# app/config/config.ymllexik_currency:
decimal_part:
precision: 2# number of digits for the decimal partround_mode: up # round mode to use (up|down|even|odd)currency_class: Lexik\Bundle\CurrencyBundle\Entity\Currency # Use your custom Currency Entitydefault_adapter: doctrine_currency_adapter # service id OR tag alias, this is adapter used by the conversion service

Initialize currencies

To initialize the currencies rate in the database run the following command:

./app/console lexik:currency:import <currency adapter identifier>

Example by using the ECB adapter, to get rates from the European Central Bank.
In the command line ecb is the value returned by the getIdentifier() method of the adapter class.

./app/console lexik:currency:import ecb

Usage

Currency conversion service

Use the convert() method from the lexik_currency.converter service:

<?php// by default the amount will rounded and the amount have to be in the default currency$convertedAmount = $container->get('lexik_currency.converter')->convert($amount, $targetCurrency);
// here the amount won't be rounded and we specify that $amount currency is 'USD'$convertedAmount = $container->get('lexik_currency.converter')->convert($amount, $targetCurrency, false, 'USD');

Retrieve managed configurations

In the controller, you can use the following line to retrieve an array of all managed currencies: