'ejs add comma every three digit

i'm using ejs for very small homepage

I wanna insert comma every three digit

Now situation

<%= product.price %> 
result = 1000000

I want like this

<%= product.price %> // some function
result 1,000,000

can you help me?



Solution 1:[1]

self answer

just pass the function to ejs

[ express ]

res.render(`${__dirname}/views/dashboard.ejs`, {
   ? numberWithCommas ? : function (x) {
     return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
   },
});

[ ejs ]
now you can call the function 

<%- numberWithCommas(product.price) %>

result
1,000,000

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 SILENMUS