Convert numbers to words - their written form.
Install with npm
npm i --save written-number
Install with bower
bower install written-number
var writtenNumber = ;; // => 'one thousand two hundred and thirty-four'
noAnd- Defaults to
false. Determines whether to use a separator. The separator is internationalized.
lang- Could be
object. Defaults to
'en'. Determines which language to use. An i18n configuration object may be passed to support external language definitions.
Currently supported languages are:
lang = "en"
- Portuguese (Brazil)
lang = "pt"
- Portuguese (Portugal)
lang = "ptPT"
lang = "es"
lang = "fr"
lang = "eo"
lang = "vi"
lang = "tr"
- English (Indian)
lang = "enIndian"
var writtenNumber = ;; // => 'mil doscientos treinta y cuatro'
var writtenNumber = ;writtenNumberdefaultslang = 'es';; // => 'cuatro mil setecientos cincuenta y ocho'
Portuguese (Brazil) Example
var writtenNumber = ;; // => 'mil duzentos e trinta e quatro'
var writtenNumber = ;; // => 'mille deux cent trente-quatre'
var writtenNumber = ;; // => 'mil ducent tridek kvar'
var writtenNumber = ;; // => 'một ngàn hai trăm và ba mươi bốn'
Configure your own language
Each language has it's own unique grammar exceptions. You can create your own language.json file in the folder "i18n" and give writtenNumber support for it. I don't think the current scheme and logic cover all the cases, but may be cover some.
'Boolean' that indicates if it use long or short
scale. This differs the
meaning of the words
trillion and so on.
'String' that separates the base cardinal numbers.
Example: 29 -> twenty
-eight. Spanish uses the conector " y ".
'String' that separates the units from the last base cardinal numbers. Example: 1234 -> one thousand two hundred and thirty-four
Base cardinals numbers. Numbers that have unique names and are used to build others.
Number units. It can be:
Object normal flow. Give support to singular and plural units. English does not need this, but spanish does.
- Object with
useBaseInsteadexception. In some languages like spanish, specific units like "ciento", use the base cardinal number instead.
useBaseException you can also specify with which unit (1 to 9) you don't
want use the base cardinal instead and use the regular behaviour.
- Object with
In some languages like spanish, specific units like "mil" does not use the base cardinal number prefix for unit 1.
- Object with
In some languages like french, specific units like "cent" does not use the plural form inside of numbers wioth trailing numbers other than 0, for example "deux cents" and "deux cent trois".
Sometimes grammar exceptions affect the base cardinal joined to the unit. You can set specific exceptions to any base cardinal number.
Without Exception (Wrong): 1232000 -> **uno** millón doscientos treinta y dos mil
With Exception: 1232000 -> **un** millón doscientos treinta y dos mil
English configuration example
Spanish configuration example
Do your changes and submit a PR. If you've write access and want to bump the
mversion [major|minor|patch] -m. That'll bump both
This code is licensed under the MIT license for Pedro Tacla Yamada. For more information, please refer to the LICENSE file.