formatCurrency

Documentation de cbk-toolkit

formatCurrency

Formate un montant avec Intl.NumberFormat — fr-FR + EUR par défaut, fallback "-" si invalide. Accepte number | string | null (supporte "99,99"). Alias FCFA → XAF (Intl affiche "FCFA" en fr-FR).

Démo en direct

Défaut EUR fr-FR

1 234,50 €

formatCurrency(1234.5)

USD en-US

$1,234.50

{ currency: "USD", locale: "en-US" }

Compact

1,25 M €

{ notation: "compact" }

Sans devise (decimal)

1 234,567

formatNumber(1234.567)

FCFA / XAF

5 000,00 FCFA

formatCurrency(5000, { currency: "XAF" }) — FCFA aussi

FCFA alias

5 000,00 FCFA

formatCurrency(5000, { currency: "FCFA" })

Test interactif

1 234,50 €

Valeur parsée: 1234.5

Cas limites

formatCurrency(null)-
formatCurrency("invalid")-
formatCurrency("99,99")99,99 €
formatCurrency(0)0,00 €
Code source — copier-coller

Basique

import { formatCurrency, formatNumber } from "@ramses1er/cbk-toolkit/client";

formatCurrency(1234.5); // "1 234,50 €"
formatCurrency("99,99"); // "99,99 €" (virgule supportée)
formatCurrency(null); // "-"
formatCurrency("invalid"); // "-"
formatNumber(1234.567); // "1 234,567"

Avec Intl options

import { formatCurrency } from "@ramses1er/cbk-toolkit/client";

// Autre devise / locale
formatCurrency(99.99, { currency: "USD", locale: "en-US" }); // "$99.99"
formatCurrency(99.99, { currency: "GBP", locale: "en-GB" }); // "£99.99"
formatCurrency(5000, { currency: "XAF" }); // "5 000,00 FCFA" (fr-FR)
formatCurrency(5000, { currency: "FCFA" }); // "5 000,00 FCFA" (alias -> XAF)
formatCurrency(5000, { currency: "XOF" }); // "5 000,00 F CFA"

// Notation compacte
formatCurrency(1250000, { notation: "compact" }); // "1,25 M €"
formatCurrency(1250000, { currency: "XAF", notation: "compact" }); // "1,25 M FCFA"

// Sans décimales
formatCurrency(1234, { maximumFractionDigits: 0 }); // "1 234 €"

// Fallback custom
formatCurrency(null, { fallback: "N/A" }); // "N/A"

// Dans un Table
const columns: Column<Product>[] = [
  { header: "Prix", render: (row) => formatCurrency(row.price, { currency: "XAF" }) },
];
API de référence
FonctionSignatureDescription
formatCurrency(value, options?) => stringMontant en devise (EUR fr-FR par défaut)
formatNumber(value, options?) => stringNombre décimal localisé sans devise
ParamTypeDéfautDescription
valuenumber | string | nullrequisMontant — "99,99" supporté, invalide → fallback
options.localestring"fr-FR"Locale Intl
options.currencystring"EUR"Devise ISO (EUR, USD, GBP...)
options.fallbackstring"-"Retour si null/invalide
options.*Intl.NumberFormatOptions—notation, minimumFractionDigits, etc.
Comportement
  • Sans options → style:currency currency:EUR min/max:2→ "1 234,50 €"
  • null / "" / NaN / Infinity → fallback
  • Parse string avec remplacement virgule→point pour support fr
  • Délègue à Intl.NumberFormat(locale, options)