Created
April 6, 2020 05:45
-
-
Save oklays/0f58d68f69cda808ecb2ec602d956f7e to your computer and use it in GitHub Desktop.
Format Rupiah Function Javascript !!!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const formatRupiah = (bilangan) => { | |
| var number_string = bilangan.toString(), | |
| sisa = number_string.length % 3, | |
| rupiah = number_string.substr(0, sisa), | |
| ribuan = number_string.substr(sisa).match(/\d{3}/g); | |
| if (ribuan) { | |
| let separator = sisa ? "." : ""; | |
| rupiah += separator + ribuan.join("."); | |
| } | |
| return rupiah; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment