How can I format price commas from 213,500 to 2,13,500?

How can I format price commas from 213,500 to 2,13,500?

datatyaani
Shopify Partner
1 0 0

current my comma's are use 213,500
but i need comma's like 2,13,500

Replies 2 (2)

Liam
Community Manager
3108 340 871

Hi Datatyaani,

 

Looking into this, it sounds like you're trying to display prices in the Indian numbering system, where values are delimited by commas after the thousands place, and then after every two digits beyond the lakh place. If so, it doesn't look like the regular currency formatting editing options will let you achieve this - but it might be possible to use a JavaScript function that formats the price in the way you need it, once it's displayed on the webpage.

 

This could be something like:

 

 

 

function formatPriceINR(x) {
    x = x.toString();
    var lastThree = x.substring(x.length - 3);
    var otherNumbers = x.substring(0, x.length - 3);
    if (otherNumbers !== '')
        lastThree = ',' + lastThree;
    var result = otherNumbers.replace(/\B(?=(\d{2})+(?!\d))/g, ",") + lastThree;
    return result;
}

var price = 213500;
console.log(formatPriceINR(price));  // Outputs: 2,13,500

 

 

 

In this script, `formatPriceINR` is a function that takes a number and returns it as a string, formatted with commas in the Indian numbering style. This function can be used in the script where prices are being displayed on your theme - and might need to be modified based on your theme. Please test it out throughly before using in on the live version of your theme.

 

It's also important to note that this script only changes the visual presentation of the number on your site, and doesn't impact how prices are stored on the admin. Hope this helps!

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

aravinthemb
Shopify Partner
4 0 0

But how can we use this in Email template? I tried Js code ,it is working for other pages like PDP,PLP,Cart....etc But in email template it is not working.How can we resolve this issue? Can anyone help me on that.