I am using magento-2.2.7. In email template, price subtotal and grandtotal is showing like that 0.5000000000045 .How to change this price in proper format. Please help me to solve it. I want to share screenshot as follow : https://paste.pics/67A5H
1 Answer
You can try this code
protected $priceHelper;
public function __construct(
\Magento\Framework\Pricing\Helper\Data $priceHelper
) {
$this->priceHelper = $priceHelper;
}
public function getFormattedPrice($price)
{
return $this->priceHelper->currency($price, true, false);
}
Using Object Manager [Not Recommended way]
<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); // Instance of Object Manager
$priceHelper = $objectManager->create('Magento\Framework\Pricing\Helper\Data'); // Instance of Pricing Helper
$price = 1000; //Your Price
$formattedPrice = $priceHelper->currency($price, true, false);
?>
Hope It helps.
-
-
you can write this code in your block and call the function where you want to use Commented Jul 25, 2019 at 5:30
-
-
which block module_sales block or module_email block ?? Commented Jul 25, 2019 at 5:33
-
is this your custom email template and are you using any module? Commented Jul 25, 2019 at 5:35