From 5eabc9c6ded4fa7018968052f556687fe551fc12 Mon Sep 17 00:00:00 2001 From: sianida26 Date: Sat, 8 Jun 2024 12:11:42 +0700 Subject: [PATCH] Added format rupiah --- apps/frontend/src/utils/formatRupiah.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 apps/frontend/src/utils/formatRupiah.ts diff --git a/apps/frontend/src/utils/formatRupiah.ts b/apps/frontend/src/utils/formatRupiah.ts new file mode 100644 index 0000000..0f8e2b1 --- /dev/null +++ b/apps/frontend/src/utils/formatRupiah.ts @@ -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 \ No newline at end of file