In magento 2, I don't know how to format cart item price.

I have a price format like this : £1,522.58 and I want this format £1522,58

I succeed to change the format of the total cart price by overriding

 getPriceFormat() method in Magento\Framework\Locale\Format.php file.

But it doesn't work for cart item total.

Do you know how to make this change ?


1 Answer 1

  1. To format the price you can put below code into your block file.

    public function __construct(\Magento\Framework\Pricing\Helper\Data $pricingHelper)
        $this->pricingHelper = $pricingHelper;
    public function getCustomFormatedPrice($myprice)
        return $this->pricingHelper->currency($myprice,true,false); 
  2. Now you can call it from your phtml file like this one.

    echo $block->getCustomFormatedPrice($myprice);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.