NumberToEnglish : Converts Arabic numerals to English
| script karma
Downloaded by 764
Comments, bugs, improvements
script versions (upload new version)
|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.
|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).
Click on the package to download.
ip used for rating: 184.108.40.206
||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".
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"
||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).
||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.