I want to convert number into currency format in magento2 like we do in Magento 1.x with this

$_coreHelper = $this->helper('core');

How to do same in Magento2?


5 Answers 5


In magento 2, there are no 'core' module. You can get this by following way inside view file(.phtml)

  • What if you just want currency symbol to the price? currency() method will used current scope currency to convert.
    – MagePsycho
    Feb 13, 2018 at 11:24
  • 2
    This does not work for prices over 1000. The number_format adds thousands separators, which causes trouble on European systems where a point is a thousand separator. For example a price of EUR 12000 returns € 12,00 which is wrong. Then you need to remove the number_format() and just pass the amount: $this->helper('Magento\Framework\Pricing\Helper\Data')->currency(50),true,false);
    – Jacques
    Mar 22, 2018 at 14:12
  • This is certainly not the best answer althoug it is voted highest and the accepted one. Better approuch is dchayka's answer: magento.stackexchange.com/a/148082/5827
    – Akif
    May 16, 2018 at 13:35
  • 3
    For those wondering, the signature is currency($value, $format = true, $includeContainer = true) Jun 20, 2018 at 14:27

What you want to do is to inject the "PriceCurrencyInterface" in the Block of the template file that you wish to use this in.


<div><?= $block->getFormatedPrice('342.4345') ?>

Item.php (Block Class of the above template... whatever that might be)

namespace \Whatever

use Magento\Framework\Pricing\PriceCurrencyInterface;
use Magento\Framework\View\Element\Template;

class Item extends Template
    /** @var PriceCurrencyInterface $priceCurrency */
    protected $priceCurrency;

    public function __construct(
        Template\Context $context,
        PriceCurrencyInterface $priceCurrency,
        array $data = []
    ) {
        parent::__construct($context, $data);
        $this->priceCurrency = $priceCurrency;

     * Function getFormatedPrice
     * @param float $price
     * @return string
    public function getFormatedPrice($amount)
        return $this->priceCurrency->convertAndFormat($amount);

This has the added benefit of displaying the correct format based on current store locale. It also offers other methods that might be helpful, check them out...

Make sure to check the method signature since you can configure the result you want to display such as the container and the precision.

priceCurrency->convertAndFormat($amount, $includeContainer, $precision)



First of all do not do currency formatting inside your view (.phtml) files, use helpers or blocks or combination of both.

The accepted answer uses number_format function which should not be used at all, at least I wouldn't go with that approach.

You can try using a model:

Model of type Magento\Directory\Model\Currency. Function format() as it's the one responsible for decimal places and formatting.

Example assuming variables $model and $product have been instantiated:

$model->format($product->getPrice(), array('symbol' => ''), false, false)

2 decimal places for formatting without $ dollar next to the amount. Pass empty array() if you want store currency appended to your amount.

  • Another benefit of using this method is working with values over $1000. The other answers don't take this number format in mind, and you end up with the incorrect prices showing up on the front end. I wish i could give you 1,000 up votes
    – circlesix
    Apr 17, 2017 at 20:32
  • So what does Magento\Directory\Model\Currency do, and why should it be used? Does it look at the current storeview currency configuration, or the currency selected by the customer?
    – Erfan
    Aug 31, 2017 at 3:57
  • 1
    @Erfan the way I see it Currency model in the Directory module is like a helper to manipulate final price value. In the example of the helper from the Framework you'll be able to convert the price to the correct currency of the store but you have no control over precision of the amount and will have to extend classes to get it customized. The Currency is the opposite where it expects the final amount but allows you to customize formatting, decimal precision, etc.
    – dchayka
    Jul 25, 2018 at 16:48

You can get this by following way inside view file(.phtml).

$price = 5.5;
  • 1
    For those wondering, the signature is currency($value, $format = true, $includeContainer = true) Jun 20, 2018 at 14:31
  • Check link bit.ly/2MKg1L4 Aug 23, 2018 at 17:30
  • This is the quickest way, if you don't want to build a separate module, just to implement the currencyInterface into Magento's Template-class. Oct 2, 2018 at 11:43
  • As I need to use the same formater in multiple places on the phtml, what can I use instead of $this-> when I call your suggestion inside of a function Oct 22, 2019 at 14:03

Using the pricing helper

namespace \Vendor\Module

class MyClass extends Template
    public $priceHelper;

    public function __construct(
        Template\Context $context,
        \Magento\Framework\Pricing\Helper\Data $priceHelper,
        array $data = []
    ) {
        parent::__construct($context, $data);
        $this->priceHelper  = $priceHelper;

    public function myCustomFunction($product) {
        return $this->priceHelper->currency($product->getPrice(),true,false);

This outputs a price and currency symbol from a given product.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.