Menu

Amounts in French words for invoices: a TypeScript function (with Moroccan dirhams as the example)
📰

Amounts in French words for invoices: a TypeScript function (with Moroccan dirhams as the example)

DEV Community: typescript·Souk Code·10 days ago
#Pbilu0o8
#devtotypescript#devto#dev#dirhams#const
Long article (1159 words) — no AI summary yet.
Reading 0:00
15s threshold

Why is an English post about Moroccan invoices? Because the problem is not only Moroccan. Any invoice in French (France, Belgium, Switzerland, Morocco, Tunisia, Senegal and more) can be asked to carry "le montant en lettres": the total written out in words under the numbers. It is a rule many developers meet only when a client in one of those markets asks for it, and English-language libraries do not cover French spelling. I work in Morocco, so my examples use dirhams, but the same code works with euros or any other currency by changing the currency name.

Here is the line you need to produce: "Arrêtée la présente facture à la somme de mille deux cent cinquante dirhams et cinquante centimes".

What you get: the five French spelling rules that cause most bugs, a dependency-free TypeScript function (0 to 999 999 999.99), and a short list of tests to write.

Where this shows up in practice

LMOUKAWIL is a Moroccan platform for auto-entrepreneur invoicing.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.