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?
i'm using ejs for very small homepage
I wanna insert comma every three digit
<%= product.price %>
result = 1000000
<%= product.price %> // some function
result 1,000,000
can you help me?
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