1function formatToCurrency(amount){
2 return (amount).toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,');
3}
4formatToCurrency(12.34546); //"12.35"
5formatToCurrency(42345255.356); //"42,345,255.36"
1(1234567.8).toFixed(2).replace(/(\d)(?=(\d{2})+\d\.)/g, '$1,') // "12,34,567.80"
1 var x=12345678;
2 x=x.toString();
3 var lastThree = x.substring(x.length-3);
4 var otherNumbers = x.substring(0,x.length-3);
5 if(otherNumbers != '')
6 lastThree = ',' + lastThree;
7 var res = otherNumbers.replace(/\B(?=(\d{2})+(?!\d))/g, ",") + lastThree;
8 alert(res);