Webkul
Services
Technologies Bagisto QloApps
iOS Android SAP BigCommerce Wix
Trusted by
Samsung Intel Toyota Walmart Disney Nokia Nestlé Decathlon
See all customers
Back to Top
DEV

Magento2 – Get Formatted Price By Currency Symbol

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

. . .

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