Added format rupiah
This commit is contained in:
parent
dc3baffd94
commit
5eabc9c6de
18
apps/frontend/src/utils/formatRupiah.ts
Normal file
18
apps/frontend/src/utils/formatRupiah.ts
Normal 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
|
||||
Loading…
Reference in New Issue
Block a user