Quick Ways To Get Formatted Price With Currency in Magento 2
You can get formatted price with currency in Magento 2 using the block method. Convert a plain number into a price format with a currency symbol using any one of the solutions given below.
Method To Get Formatted Price With Currency In Magento 2:
1 2 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); } |
Use the Comments section below if you have any doubts about the topic. I’d help your way out.
Please share the solution with fellow Magento developers via social media.
Thank you.
Sanjay Jethva
Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe.
His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.
2 Comments
How to get price with currency symbol
Hello Pratik,
To get the price with a currency symbol, use $priceHelper->convertAndFormat($price) as shown in the above post.
Thank you.