Skip to content

Instantly share code, notes, and snippets.

View leandrocustodio's full-sized avatar

Leandro Custodio leandrocustodio

  • TheoremOne
  • Brazil
View GitHub Profile
@humrochagf
humrochagf / currency.js
Created May 16, 2015 00:39
Javascript currency formating with comma decimal separation
function number_to_money(num, currency) {
currency = typeof currency !== 'undefined' ? currency : '$';
return currency + ' ' + num.toFixed(2).replace('.', ',').replace(/(?=(\d{3})+\,)/g, '.').replace(/^\./,'');
};
var numbers = [1, 12, 123, 1234, 12345, 123456, 1234567, 12345.67];
for (var i = 0; i < numbers.length; i++) {
document.write(number_to_money(numbers[i], 'R$') + '<br />');
};