function formatRp(number) { var number_string = parseInt(number).toString(), split = number_string.split(","), remainder = split[0].length % 3, amount = split[0].substr(0, remainder), thousand = split[0].substr(remainder).match(/\d{3}/gi); if (thousand) { separator = remainder ? "." : ""; amount += separator + thousand.join("."); } amount = split[1] != undefined ? amount + "," + split[1] : amount; return "Rp" + amount; }