Back to Top

Magento2 – Get Formatted Price By Currency Symbol

Updated 22 February 2024

If having an issue in getting the formatted price in magento2 in the desired currency then no need to worry about this. Here, we will see how to get the formatted price with the currency symbol in Magento2.

<?php
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); // Instance of Object Manager
    $currencyModel = $objectManager->create('Magento\Directory\Model\Currency'); // Instance of Currency Model
    $price =  500; //Your Price
    //get currency symbol by currency code
    $currencyCode = 'USD';
    $currencySymbol = $currencyModel->load($currencyCode)->getCurrencySymbol();
    $precision = 2;   // for displaying price decimals 2 point
    //get formatted price by currency
    $formattedPrice = $currencyModel->format($price, ['symbol' => $currencySymbol, 'precision'=> $precision], false, false);
?>

Formatted price is $500.00

Searching for an experienced
Magento 2 Company ?
Find out More
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


2 comments

  • Samir
    • Anuj Gupta (Moderator)
  • Back to Top

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home