Bhaveshpp

Professional Magento Developr - Healp eachother to grow

Magento 2: price currency formate

20 Jan 2022 » magento2, php

    /** @var \Magento\Framework\Pricing\Helper\Data */
    public $priceData;
    
    /**
     * constructor
     * @param \Magento\Framework\Pricing\Helper\Data $priceData
     */
    public function __construct(
        \Magento\Framework\Pricing\Helper\Data $priceData
    ) {
        $this->priceData = $priceData;
    }

   public function roundPrice($price,$format = true)
   {
      if ($format) {
         return $this->priceData->currency(round($price),true,false);
      }else{
         return round($price);
      }
   }

Thanks.