How to format integer in currency with javascript? [duplicate]

-1

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

    
asked by anonymous 08.09.2015 / 16:00

2 answers

2

Solution with JS Regex

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

Jose, you can use the jQuery MaskMoney plugin

link

The usage is basically this:

$("#id_input").maskMoney();
    
08.09.2015 / 16:07