sponsor Vim development Vim logo Vim Book Ad

NumberToEnglish : Converts Arabic numerals to English

 script karma  Rating 4/1, Downloaded by 1314  Comments, bugs, improvements  Vim wiki

created by
Salman Halim
script type
Converts a number (such as -1234) to English (negative one thousand two hundred thirty four); handles the biggest integer Vim can work with (billions).

This actually figures out the English value by crunching the numbers (not through abbreviations) and thus doesn't have any startup overhead.

Usage: call the function NumberToEnglish and pass it the number; optionally, a second parameter can be passed in which, if not 1, will cause the return
value's first letter to be capitalized (Two hundred thirty four vs. two hundred thirty four).

Two insert-mode mappings have been provided for convenience to make this happen on the currently typed number while typing.

<Plug>NumberToEnglish: converts the (positive only) number to English

<Plug>CNumberToEnglish: converts the (positive only) number to English, capitalizing the first letter

Two identical version of these mappings that start with a D (for "Detailed") will append the original number in parentheses after the expansion.
install details
Just drop it into your plugin directory and, if you like, set up the mappings; for example:

imap <leader>ne <Plug>NumberToEnglish
imap <leader>nd <Plug>DNumberToEnglish
imap <leader>nE <Plug>CNumberToEnglish
imap <leader>nD <Plug>DCNumberToEnglish

See the notes for version 1.3 if the introduction of another language is desired; the system isn't perfect, but should work for most Indo-European languages that follow the same basic numbering scheme as English (French is provided as an example).

Note: Requires the use of GetVar (http://vim.sourceforge.net/scripts/script.php?script_id=353).

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
NumberToEnglish enh-ordinal.zip 1.5 2012-04-17 7.0 Salman Halim Significant number of changes; all credit goes to Ingo Karkat--thank you, Ingo:

- Added parallel function and mappings for ordinal numbers ("forty-second"), also configurable via g:numberToEnglish_ordinal_... variables.
- Made remaining hard-coded words configurable via variables g:numberToEnglish_zero, g:numberToEnglish_negative.
- Allowed to use hyphen separator for numbers in range 21-99; g:numberToEnglish_useHyphen.
- Split into plugin and autoload script to minimize footprint.
- Change default to let g:numberToEnglish_useAnd = 1
- Fix additional comma in "one thousand, and one".
NumberToEnglish.vim 1.4 2010-10-05 7.0 Salman Halim Version 1.4

Added an option to put in the word "and" (nine hundred AND twenty); off by default to retain old behavior:

let g:numberToEnglish_useAnd = 1

Added another configuration variable (French, in this example):

let g:numberToEnglish_and = "et"

Sections are now separated by commas; for example, "12345" becomes "twelve thousand, three hundred and forty five"
NumberToEnglish.vim 1.3 2009-03-06 7.0 Salman Halim Made the plugin accept global values for overriding the returned string; useful for changing the language, for example. Place the following in your _vimrc for

let g:numberToEnglish_digits = [ "", "un",   "deux",  "trois",  "quatre",   "cinq",      "six",      "sept",         "huit",         "neuf" ]
let g:numberToEnglish_teens  = [ "", "onze", "douze", "treize", "quatorze", "quinze",    "seize",    "dix-sept",     "dix-huit",     "dix-neuf" ]
let g:numberToEnglish_tens   = [ "", "dix",  "vingt", "trente", "quarante", "cinquante", "soixante", "soixante dix", "quatre vingt", "quatre vingt dix" ]

let g:numberToEnglish_scale = [ "", "mille", "million", "billion" ]

let g:numberToEnglish_hundred = "cent"

This change necessitates the use of GetVar (http://vim.sourceforge.net/scripts/script.php?script_id=353). Technically, the usage of GetVar allows the setting
of any combination of these variables on a per-window, buffer or tab level (allowing different languages, capitalizations, etc., depending upon the buffer
type, for example).
NumberToEnglish.vim 1.2 2009-03-03 7.0 Salman Halim Added two new mappings:

<Plug>DNumberToEnglish and <Plug>DCNumberToEnglish -- the D is short for "Detailed".

Differs from the versions without the D in that it places the original number at the end of the expanded version:

Thus, 12341234 becomes twelve million three hundred forty one thousand two hundred thirty four (12341234).

Version 1.1 (not uploaded):

Took the hard-coded values out of the functions into script-local variables -- no sense defining them every time.
NumberToEnglish.vim 1.0 2009-02-27 7.0 Salman Halim Initial upload
ip used for rating:

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
Vim at Github