Skip to content

Instantly share code, notes, and snippets.

@iqbalfasri
Last active November 8, 2019 10:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iqbalfasri/0d911cecd59cc0734c36af7cb008e262 to your computer and use it in GitHub Desktop.
Save iqbalfasri/0d911cecd59cc0734c36af7cb008e262 to your computer and use it in GitHub Desktop.
Simple format for Indonesian Rupiah (curency)
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