Skip to content

fix(whatsapp): format receipt amounts with Intl.NumberFormat for correct locale currency placement #196

Closed

Description

@khaira777

Summary

In frontend/src/lib/whatsapp-share.ts, the helper function formatAmount hardcodes the currency symbol directly as a prefix string before the formatted number (${currency}${amount.toLocaleString(...)}). In international locales where currency symbols appear after the amount (or require specific spacing, e.g., German/French EUR formatting 10,00 € or Swedish SEK 100 kr), the generated WhatsApp receipt text is malformed.

Root Cause

In frontend/src/lib/whatsapp-share.ts line 139:

function formatAmount(value: number | string, currency: string, locale: string): string {
  const amount = Number(value);
  return `${currency}${(Number.isFinite(amount) ? amount : 0).toLocaleString(locale, { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`;
}

Concatenating currency as a hardcoded prefix ignores standard locale formatting rules provided by standard browser and Node.js Intl APIs.

Why It Matters

Customers receiving WhatsApp e-bills in non-USD/INR locales receive incorrectly formatted billing text.

Expected Behavior

Receipt totals and item amounts follow the regional formatting rules of the tenant's selected country and currency code.

Actual Behavior

Currency symbols are always prepended to amounts regardless of the locale.

Affected Files

  • frontend/src/lib/whatsapp-share.ts

Suggested Implementation Direction

Use new Intl.NumberFormat(locale, { style: 'currency', currency: tenantCurrency }) or leverage the existing currency formatting hook logic to generate localized price strings.

Activity

  1. itsbkm commented on Jul 29, 2026

    @itsbkm
    Contributor

    Fixed in 1524019: formatAmount() now uses Intl.NumberFormat({ style: 'currency', currency }) instead of concatenating the currency symbol as a string prefix, so amounts render correctly across locales.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions