Search

Sep 20, 2023

Magento 2: Format Price

In phtml file

/** @var $priceHelper Magento\Framework\Pricing\Helper\Data */
$priceHelper = $this->helper(Magento\Framework\Pricing\Helper\Data::class);
echo $priceHelper->currency(100.57, true, false);


In php file

3
4
5
6
7
8
9
10
use Magento\Framework\Pricing\Helper\Data
protected $priceHelper;
public function __construct(Data $priceHelper)
{
    $this->priceHelper = $priceHelper;
}
public function getFormattedPrice($price)
{
    return $this->priceHelper->currency($price, true, false);
}

No comments:

Post a Comment