Indian rupee comma format
JavaScript
function formatNumber(num) {
num = num + '' || '';
// works for integer and floating as well
var numberAndDecimal = num.split('.');
var decimals = numberAndDecimal[1] || null;
numberAndDecimal = numberAndDecimal[0].replace(/(\d)(?=(\d\d)+\d$)/g, "$1,");
num = decimals ? numberAndDecimal + '.' + decimals : numberAndDecimal;
return num;
}
alert(formatNumber(prompt("Enter Number", 1234567.89)));