Is it possible to get the price without currency symbol, or a way to put a div around the currency symbol to hide it with css?

$block->formatCurrency($block->getDisplayValue(), (bool)$block->getIncludeContainer())

If I remove the $block->formatCurrency I get the price without currency symbol, but a 1 will be added at the end of the price.

So I would like to put a div around the currency symbol and hide it with CSS.

Someone who can help me with that?

EDIT: I also want to add ,- behind the price.


Yes it is possible to get price without currency symbol by using below approach

Instantiate \Magento\Directory\Model\Currency $priceCurrencyFormat class in constructor and use below code

$this->priceCurrencyFormat->format($product->getPrice(), ['precision'=>0, 'display'=>\Zend_Currency::NO_SYMBOL], 0);

In second param of format() func you can also customize the price precision based on your requirement.

You could also use below code to get your result, but it is not a good approach

$objectManager    = \Magento\Framework\App\ObjectManager::getInstance();
$priceCurrencyFormat = $objectManager->get('Magento\Directory\Model\Currency');
$priceFormat = $priceCurrencyFormat->format($product->getPrice(), ['precision'=>0, 'display'=>\Zend_Currency::NO_SYMBOL], 0);
echo $priceFormat."-";
  • Hi, I can't find the file to edit. Are you sure is the correct path for Magento 2? – n00bly May 8 at 10:29
  • Directly editing the core file is not recommended, you should override the file in which you need your changes. In that overdid file (say you overdid any block file ) you can create the function with the above code and call it in your file. – Prabhu M. May 8 at 10:54
  • I have updated my answer, placing those 4 lines of code in your desired files will give you your desired result. – Prabhu M. May 8 at 11:13

May be this will help you

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$currency = $objectManager->get('Magento\Directory\Model\Currency');
$price = 100;
echo $currency->format($price, ['display'=>\Zend_Currency::NO_SYMBOL], false);

You guys can use this extension.


Which is paid.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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