How to format whole number in currency with javascript?

Asked

Viewed 3,817 times

-1

Example var number = 3500; I want you to return 3,500

2 answers

2


Solution with Regex Do JS

function currencyFormat (num) {
    return num.toFixed(2).replace(".", ",").replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,")
}

1

  • Thanks for the feedback, I tried to use maskMoney but it didn’t work so I used JS regex .

Browser other questions tagged

You are not signed in. Login or sign up in order to post.