Magento – M2.3.1 – Remove currency symbol from price

currencycurrency-symbolmagento2price

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.

Best Answer

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."-";
Related Topic