{"id":7389,"date":"2019-10-04T12:27:27","date_gmt":"2019-10-04T06:57:27","guid":{"rendered":"https:\/\/www.hiddentechies.com\/blog\/?p=7389"},"modified":"2019-10-04T16:02:11","modified_gmt":"2019-10-04T10:32:11","slug":"magento-2-get-formatted-price-with-currency","status":"publish","type":"post","link":"https:\/\/www.hiddentechies.com\/blog\/magento-2\/magento-2-get-formatted-price-with-currency\/","title":{"rendered":"Magento 2 &#8211; How to Get Formatted Price With Currency"},"content":{"rendered":"<p>In this post I am going to explain how to get formatted price with currency in Magento 2.<\/p>\n<p><strong>1. Using Dependency Injection<\/strong><\/p>\n<p>Add below code snippet in Block class.<\/p>\n<pre class=\"lang:default decode:true \">protected $_priceHelper;\r\n    \r\npublic function __construct(\r\n\t\\Magento\\Backend\\Block\\Template\\Context $context,\r\n\t\\Magento\\Framework\\Pricing\\Helper\\Data $priceHelper,\r\n\tarray $data = []\r\n) \r\n{\r\n\t$this-&gt;_priceHelper = $priceHelper;\r\n\tparent::__construct($context, $data);\r\n}\r\n\r\npublic function getFormattedPrice($price) \r\n{\r\n\t$formattedPrice = $this-&gt;_priceHelper-&gt;currency($price, true, false);\r\n\treturn $formattedPrice;\r\n}<\/pre>\n<p>Add below code snippet in template file.<\/p>\n<pre class=\"lang:default decode:true \">\/\/Your Price\r\n$price = 499;\r\n\r\n\/\/ Get Formatted Price\r\n$formattedPrice = $block-&gt;getFormattedPrice($price);\r\n\r\necho $formattedPrice;<\/pre>\n<p><strong>2. Using Object Manager<\/strong><\/p>\n<pre class=\"lang:default decode:true \">$objectManager = \\Magento\\Framework\\App\\ObjectManager::getInstance();\r\n\r\n$priceHelper = $objectManager-&gt;create('Magento\\Framework\\Pricing\\Helper\\Data');\r\n\r\n\/\/Your Price\r\n$price = 499; \r\n\r\n\/\/ Get Formatted Price\r\n$formattedPrice = $priceHelper-&gt;currency($price, true, false);\r\n\r\necho $formattedPrice;<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this post I am going to explain how to get formatted price with currency in Magento 2. 1. Using Dependency Injection Add below code snippet in Block class. protected $_priceHelper; public function __construct( \\Magento\\Backend\\Block\\Template\\Context $context, \\Magento\\Framework\\Pricing\\Helper\\Data $priceHelper, array $data = [] ) { $this-&gt;_priceHelper = $priceHelper; parent::__construct($context, $data); } public function getFormattedPrice($price) { $formattedPrice&#8230; <\/p>\n<div class=\"actions\"><a href=\"https:\/\/www.hiddentechies.com\/blog\/magento-2\/magento-2-get-formatted-price-with-currency\/\">Continue Reading<\/a><\/div>\n","protected":false},"author":1,"featured_media":7417,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[59],"tags":[10,27],"_links":{"self":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts\/7389"}],"collection":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/comments?post=7389"}],"version-history":[{"count":1,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts\/7389\/revisions"}],"predecessor-version":[{"id":7390,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts\/7389\/revisions\/7390"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/media\/7417"}],"wp:attachment":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/media?parent=7389"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/categories?post=7389"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/tags?post=7389"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}