Added format rupiah

This commit is contained in:
sianida26 2024-06-08 12:11:42 +07:00
parent dc3baffd94
commit 5eabc9c6de

View File

@ -0,0 +1,18 @@
/**
* Formats a number into the Indonesian Rupiah currency format.
*
* @param value - The number to be formatted.
* @returns A string representing the formatted Rupiah value.
*
* * @example
* ```
* const rupiahValue = formatRupiah(123456789);
* console.log(rupiahValue); // Output: "Rp 123.456.789"
* ```
*/
function formatRupiah(value: number): string {
const formatted = value.toString().replace(/\B(?=(\d{3})+(?!\d))/g, '.');
return `Rp ${formatted}`;
}
export default formatRupiah