i want do number formatting in Javascript.. and i use the following method num.toLocaleString() which will work for Firefox, IE but doesnt work for Google Chrome.. Wat i nee
A bit of voodoo can implement your own number formatting. You could build this into String.prototype, but I didnt want that, since its localized.
function reverse(str) {
return str.split('').reverse().join('');
}
function num2str(num) {
var str = num+"";
// european
// return reverse(reverse(str.replace('.',',')).replace(/\d{3}/g,'$&.').replace(/\.$/,''));
// american
return reverse(reverse(str).replace(/\d{3}/g,'$&,').replace(/\,$/,''));
}
and then its
> console.log(25000.45)
> 25,000.45