format-currency.ts 363 B

1234567891011121314
  1. const formatter = new Intl.NumberFormat("en-US", {
  2. style: "currency",
  3. currency: "USD",
  4. })
  5. export const formatCurrency = (amount: number | null | undefined) => {
  6. if (amount === null || amount === undefined) {
  7. return "-"
  8. }
  9. return formatter.format(amount)
  10. }
  11. export const parsePrice = (price?: string) => (price ? parseFloat(price) * 1_000_000 : undefined)