Last active
November 8, 2019 10:35
-
-
Save iqbalfasri/0d911cecd59cc0734c36af7cb008e262 to your computer and use it in GitHub Desktop.
Simple format for Indonesian Rupiah (curency)
This file contains 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 toRupiah = price => { | |
return Math.abs(price) | |
.toString() | |
.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, '$1.'); | |
}; | |
/** | |
* | |
* example return | |
* @returns Rp 120.000 | |
*/ | |
export const toRupiahWithPrefix = price => { | |
const priceFormatted = Math.abs(price) | |
.toString() | |
.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, '$1.'); | |
return `Rp ${priceFormatted}`; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment