---
title: "How to Set Price Format using JavaScript in Magento 2"
url: "https://magecomp.com/blog/set-price-format-using-javascript-magento-2/"
date: "2022-02-18T15:06:59+00:00"
modified: "2025-02-18T06:02:01+00:00"
author:
  name: "Dhiren Vasoya"
  url: "https://magecomp.com/"
categories:
  - "How To"
  - "Magento 2"
word_count: 269
reading_time: "2 min read"
summary: "Hello Magento Friends,"
description: "You can set price format using JavaScript in Magento 2. For that, you need to use the Magento_Catalog/js/price-utils file. "
keywords: "How To, Magento 2"
language: "en"
schema_type: "Article"
related_posts:
  - title: "How to Assign Product Position for a Specific Category in Magento 2?"
    url: "https://magecomp.com/blog/assign-product-position-for-a-specific-category-magento-2/"
  - title: "Magento 2: How to Get All Downloadable Links Details from the Downloadable Product Programmatically"
    url: "https://magecomp.com/blog/magento-2-get-all-downloadable-links-details-from-the-downloadable-product-programmatically/"
  - title: "How to remove custom options price from the dropdown in Magento 2"
    url: "https://magecomp.com/blog/remove-custom-options-price-dropdown-magento-2/"
---

# How to Set Price Format using JavaScript in Magento 2

_Published: February 18, 2022_  
_Author: Dhiren Vasoya_  

![How to Set Price Format using JavaScript in Magento 2](https://magecomp.com/blog/wp-content/uploads/2022/02/How-to-Set-Price-Format-using-JavaScript-in-Magento-2-1024x512.webp)

**Hello Magento Friends,**

Today I am going to explain How to Set Price Format using JavaScript in Magento 2.
[![Magento Malware Removal](https://magecomp.com/blog/wp-content/uploads/2023/04/Magento-Malware-Removal-CTA-1.webp)](https://magecomp.com/magento-malware-removal.html)

At the time of [Magento 2 development](https://magecomp.com/magento-development-services), you may need to pass the price amount to js and display the currency from the js. At that time you can change the price format using JavaScript in Magento 2. You can convert plain number into price format with currency symbol using JavaScript in Magento 2.
## Steps to Set Price Format using JavaScript in Magento 2:
**Step 1:** You need to use the below Magento file
**Magento_Catalog\js\price-utils**

If you have already created a javascript file then just add the **getFormattedPrice()** function and define the **Magento_Catalog\js\price-utils** file into js.
File Path – **app\code\Vendor\Extension\view\frontend\web\js\checkpriceformate.js**

```
define([
    'ko',
    'Magento_Catalog/js/price-utils'
], function (
    ko,
    priceUtils
) {
    'use strict';

    return {

        getFormattedPrice: function (price)
        {
            var priceFormat = {
                decimalSymbol: '.',
                groupLength: 3,
                groupSymbol: ",",
                integerRequired: false,
                pattern: "$%s",
                precision: 2,
                requiredPrecision: 2
            };

            return priceUtils.formatPrice(price, priceFormat);
        }
    }
});
```

**Step 2:** After that call **getFormattedPrice()** function where you want and it returns the price as per the below format.
Price Formate : $12.00
[![Magento 2 Speed & Performance Optimization Services](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Speed-Performance-Optimization-Services-CTA-3.webp)](https://magecomp.com/magento-performance-optimization.html)

**Step 3:** After adding this code run the below commands
```
php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy -f
php bin/magento cache:flush
```

## Conclusion:
Accordingly, you can set the price format with the help of JavaScript in Magento 2. You may also like to read – [**Get Formatted Price with Currency using Block File in Magento 2**](https://magecomp.com/blog/get-formatted-price-currency-magento-2/)

In case of any issues, you can reach out to me via the comment box. Share the article on your social media platforms and stay updated with us!
[![hyva theme development](https://magecomp.com/blog/wp-content/uploads/2025/02/hyva-theme-development-CTA-1.webp)](https://magecomp.com/services/hyva-theme-development/)

**Happy Coding!**


---

_View the original post at: [https://magecomp.com/blog/set-price-format-using-javascript-magento-2/](https://magecomp.com/blog/set-price-format-using-javascript-magento-2/)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-08-21 06:21:56 UTC_  
