diff --git a/public/assets/js/forms/rupiah-format.js b/public/assets/js/forms/rupiah-format.js index e39745c..f90e5ae 100644 --- a/public/assets/js/forms/rupiah-format.js +++ b/public/assets/js/forms/rupiah-format.js @@ -1,24 +1,21 @@ $(document).ready(function () { $(".rupiah-format").on("keyup", function (e) { - $(this).val(formatRupiah($(this).val(), "Rp")); + $(this).val(formatRupiah($(this).val(), "Rp. ")); }); - function formatRupiah(number, prefix) { - var numberString = number.replace(/[^,\d]/g, "").toString(), - split = numberString.split(","), - remainder = split[0].length % 3, - rupiah = split[0].substr(0, remainder), - thousands = split[0].substr(remainder).match(/\d{3}/gi); + function formatRupiah(angka, prefix) { + var number_string = angka.replace(/[^,\d]/g, "").toString(), + split = number_string.split(","), + sisa = split[0].length % 3, + rupiah = split[0].substr(0, sisa), + ribuan = split[0].substr(sisa).match(/\d{3}/gi); - if (thousands) { - separator = remainder ? "." : ""; - rupiah += separator + thousands.join("."); + if (ribuan) { + separator = sisa ? "." : ""; + rupiah += separator + ribuan.join("."); } - if (split[1] != undefined) { - rupiah = rupiah + "," + split[1].substr(0, 2); - } - - return prefix == undefined ? rupiah : rupiah ? prefix + rupiah : ""; + rupiah = split[1] != undefined ? rupiah + "," + split[1] : rupiah; + return prefix == undefined ? rupiah : rupiah ? "Rp. " + rupiah : ""; } });