ChemPal Documentation - v1.18.0
    Preparing search index...

    Function formatWithSymbol

    • Formats an amount with its currency symbol (from CURRENCY_SYMBOL_MAP), e.g. "ƒ43.50". Uses the symbol map rather than Intl's currency style so currencies whose Intl symbol is their code (e.g. ANG → "ANG") still render the proper glyph (ANG → "ƒ"), matching the drawer's price-range adornment. The number is grouped/decimal-formatted in the runtime locale; falls back to the raw code when no symbol is known.

      Parameters

      • currency: string

        The ISO currency code (e.g. "ANG").

      • amount: number

        The numeric amount to format.

      • maximumFractionDigits: number = 2

        Upper bound on decimal places (default 2). Raise it for small per-unit prices so $0.0042 doesn't collapse to $0.00.

      Returns string

      The symbol-prefixed amount, e.g. "€18.00".

      formatWithSymbol("USD", 19.99); // => "$19.99"
      formatWithSymbol("ANG", 43.5); // => "ƒ43.50"
      formatWithSymbol("USD", 0.0042, 4); // => "$0.0042"
      export function formatWithSymbol(
      currency: string,
      amount: number,
      maximumFractionDigits = 2,
      ): string {
      const symbol = CURRENCY_SYMBOL_MAP[currency] ?? currency;
      const formatted = new Intl.NumberFormat(undefined, {
      minimumFractionDigits: 2,
      maximumFractionDigits,
      }).format(amount);
      return `${symbol}${formatted}`;
      }