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