How To convert digits ,amounts and numbers to words with JavaScript (English,French and Spanish )

When I was developing a business app for a client using Electron and JavaScript the client requested if the app can automatically convert the typed numbers to their equivalent written form in French language I said OK but I was worry about the accuracy of the algorithm that of course i’m going to invent in order to convert numbers into words .This might be simple in English but can be intimidating in French since it has more and complex grammatical rules but thanks God before I even started to think about my own algorithm I stumbled upon a very helpful JavaScript library/npm package that does numbers to words conversions in multiple languages starting with English ,French and Spanish and you can also define your own language files for any other language that you need to support .

You can use the library with Node.js by first installing it via npm

npm i --save written-number

Actually the library can also be used without Node.js in the browser .In this case you can install it via Bower

bower install written-number

Next you need to require the library if you are using it with Node.js

var writtenForm = require('written-number');
var wf = writtenForm(1000); 
console.log(wf); // => 'one thousand'

The library converts by default to English language but you can easilly specify your target language .In my case I needed French so all I had to do is adding

writtenForm.defaults.lang = 'fr';

Just after require

The full example is

var writtenForm = require('written-number');
writtenForm.defaults.lang = 'fr';
var wf = writtenForm(1000); 
console.log(wf); // => 'Mille'

You can also change the language with each function call by passing it as a paramter

writtenForm(1000, { lang: 'fr' });

And if you want to omit the “AND” between words in the written form you can also specify another option which noAnd .By default it’s set to false

writtenForm(1000, { lang: 'fr',noAnd : true });

As I mentioned before you can also add support for your own language if it’s not already supported .For more information you can visit their GitHub repository

Other librairies for spelling out numbers


It converts numbers to their written form in English, French, Indonesian, Dutch or Danish .

You can install via NPM by

npm install spell-it

Then use

var spell = require('spell-it') ('fr');
// quarante


To install Umpteen use NPM

npm install umpteen

Then just

var spellIt = require('umpteen');
console.log(spellIt.spellItOut(40)); // forty


I hope this was helpful for you as it was for me .Thanks for reading and see you for another tutorial .

Note: We also publish our tutorials on Medium and If you prefer reading in these platforms, you can follow us there to get our newest articles.

You can reach the author via Twitter:

About the author

Ahmed Bouchefra
is a web developer with 5+ years of experience and technical author with an engineering degree on software development. You can hire him with a click on the link above or contact him via his LinkedIn account. He authored technical content for the industry-leading websites such as SitePoint, Smashing, DigitalOcean, RealPython, freeCodeCamp, JScrambler, Pusher, and Auth0. He also co-authored various books about modern web development that you can find from Amazon or Leanpub

Get our Learn Angular 8 in 15 Easy Steps ebook in pdf, epub and mobi formats, plus a new Angular 8 tutorial every 3 days.

comments powered by Disqus Protection Status