koperasi/services/frontend/app/utils/to-rupiah.ts

10 lines
328 B
TypeScript
Raw Permalink Normal View History

2025-08-08 07:12:40 +00:00
function toRupiah(value: number | string): string {
const numberValue = typeof value === "string" ? Number.parseFloat(value) : value;
if (Number.isNaN(numberValue)) {
throw new Error("Invalid number");
}
return numberValue.toLocaleString("id-ID", { style: "currency", currency: "IDR" });
}
export default toRupiah;