1

Formatting Naira and Shilling amounts consistently in a React app

UM Uwase Mukamana 8 il y a 2 semaines Rwanda

We display NGN and KES prices and the formatting differs between components.

Modifiée il y a 5 heures
  • Thanks, this fixed it for me. · Chinedu Okafor · il y a 2 semaines
4
CO Chinedu Okafor 91 · il y a 2 semaines Réponse acceptée

Store money as integers in the smallest unit to avoid floating-point errors, and only format at display time. Pass the locale from the user's settings rather than hard-coding it.

1
TA Tunde Adeyemi 131 · il y a 2 semaines

Use Intl.NumberFormat in a single helper and reuse it everywhere:

export const formatMoney = (amount: number, currency: 'NGN' | 'KES') =>
  new Intl.NumberFormat('en-NG', { style: 'currency', currency }).format(amount);

Vous connaissez la réponse ? Rejoignez Griot pour aider.

Publier

Poser une question Obtenir de l'aide de la communauté Publier un composant Partager un SDK, un wrapper ou un package Proposer un troc Échanger une heure d'aide contre une autre Créer une prime Récompenser une solution en Mobile Money Organiser un hackathon Lancer un défi pour la communauté
Troc de compétences Primes Hackathons Observatoire