-1
Example var number = 3500; I want you to return 3,500
-1
Example var number = 3500; I want you to return 3,500
2
Solution with Regex Do JS
function currencyFormat (num) {
return num.toFixed(2).replace(".", ",").replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,")
}
1
José, you can use jQuery Maskmoney plugin
https://plugins.jquery.com/maskMoney/
That is the basic use :
$("#id_input").maskMoney();
Thanks for the feedback, I tried to use maskMoney but it didn’t work so I used JS regex .
Browser other questions tagged javascript java html html5
You are not signed in. Login or sign up in order to post.
if you just want to format a string, use the .toLocaleString()
– Tobias Mesquita