Essays/Number in Words

From J Wiki
Jump to navigation Jump to search

English

The name in English of a non-negative integer is formed on groups of 3 decimal digits, starting from the right. Each group is suffixed with its name, and a group of three 0-digits is omitted (unless all groups are all 0-digits, in which case the name is "zero"). British usage differs from American usage by inserting an "and" between "hundred" and trailing tens and ones. For example:

British American
23456 twenty-three thousand, four hundred and fifty-six twenty-three thousand, four hundred fifty-six
1000230046 one billion, two hundred and thirty thousand, forty-six one billion, two hundred thirty thousand, forty-six

Numbers of the form 10^3*n are named as follows: 10^3 is thousand; 10^6 is million; and for k>1 the name for 10^3*1+k is the Latin name for k suffixed by illion. For example, 10^27 is octillion, where (10^27) = 10^3*1+8 and octo is 8 in Latin.

The logic can be implemented as follows:

u=. ;:'one two three four five six seven eight nine'
v=. ;:'ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen'
t=. ;:'twenty thirty forty fifty sixty seventy eighty ninety'
EN100=: '' ; u , v , , t ,&.>/ '';'-',&.>u

z=. '' ; 'thousand' ; (;:'m b tr quadr quint sext sept oct non'),&.> <'illion'
u=. ;:'un duo tre quattuor quin sex septen octo novem'
t=. (;:'dec vigint trigint quadragint quinquagint sexagint septuagint octogint nonagint'),&.><'illion'
ENU=: z , (, t ,~&.>/ '';u) , <'centillion'

en3=: 4 : 0
 'p q'=. 0 100#:y
 (p{::EN100),((*p)#' hundred'),((p*&*q)#x),q{::EN100
)

en=: 4 : 0
 d=. 1000&#.^:_1 y
 assert. (0<:y) *. ((=<.)y) *. d <:&# ENU
 c=. x&en3&.> (*d)#d
 ((0=y)#'zero') , (-2+*{:d) }. ; , c,.(<' '),.(ENU{~I.&.|.*d),.<', '
)

uk=: ' and '&en   NB. British
us=: ' '    &en   NB. American

For example:

   uk 123456789
one hundred and twenty-three million, four hundred and fifty-six thousand, seven hundred and eighty-nine
   us 123456789
one hundred twenty-three million, four hundred fifty-six thousand, seven hundred eighty-nine

   uk 1000007
one million, seven
   us 1000007
one million, seven

   uk 10^300x
one novemnonagintillion
   us 10^300x
one novemnonagintillion

   2^200x
1606938044258990275541962092341162602522202993782792835301376
   1000&#.^:_1 ] 2^200x
1 606 938 44 258 990 275 541 962 92 341 162 602 522 202 993 782 792 835 301 376

   _80 ]\ uk 2^200x
one novemdecillion, six hundred and six octodecillion, nine hundred and thirty-e
ight septendecillion, forty-four sexdecillion, two hundred and fifty-eight quind
ecillion, nine hundred and ninety quattuordecillion, two hundred and seventy-fiv
e tredecillion, five hundred and forty-one duodecillion, nine hundred and sixty-
two undecillion, ninety-two decillion, three hundred and forty-one nonillion, on
e hundred and sixty-two octillion, six hundred and two septillion, five hundred
and twenty-two sextillion, two hundred and two quintillion, nine hundred and nin
ety-three quadrillion, seven hundred and eighty-two trillion, seven hundred and
ninety-two billion, eight hundred and thirty-five million, three hundred and one
 thousand, three hundred and seventy-six
   _80 ]\ us 2^200x
one novemdecillion, six hundred six octodecillion, nine hundred thirty-eight sep
tendecillion, forty-four sexdecillion, two hundred fifty-eight quindecillion, ni
ne hundred ninety quattuordecillion, two hundred seventy-five tredecillion, five
 hundred forty-one duodecillion, nine hundred sixty-two undecillion, ninety-two
decillion, three hundred forty-one nonillion, one hundred sixty-two octillion, s
ix hundred two septillion, five hundred twenty-two sextillion, two hundred two q
uintillion, nine hundred ninety-three quadrillion, seven hundred eighty-two tril
lion, seven hundred ninety-two billion, eight hundred thirty-five million, three
 hundred one thousand, three hundred seventy-six

French

The name in French of a non-negative integer is formed on groups of 3 digits, starting from the right. Each group is suffixed with its name, and a group of three 0-digits is omitted (unless all groups are all 0-digits, in which case the name is "zéro").

Numbers of the form 10^3*k are named as follows: 10^3 6 9 are mille, million, and milliard; and for k>1 , the name for 10^6*k is the Latin for k suffixed by illion and the name for 10^(6*k)+3 is the Latin for k suffixed by illiard. For example, 10^48 is octillion, where (10^48) = 10^6*8 and octo is 8 in Latin.

There are a few idiomatic rules:

a. 71 is "soixante et onze" but 72 is "soixante-douze", 73 is "soixante-treize", etc.

b. Numbers between 100 and 199 omit the leading "un". Thus 175 is "cent soixante-quinze" but 275 is "deux cent soixante-quinze".

c. Likewise, numbers between 1000 and 1999 omit the leading "un".

The logic can be implemented as follows:

Work in Progress

u=. <;._1 ' un deux trois quatre cinq six sept huit neuf dix'
v=. <;._1 ' onze douze treize quatorze quinze seize dix-sept dix-huit dix-neuf'
t=. <;._1 ' vingt trente quarante cinquante soixante soixante-dix quatre-vingt quatre-vingt-dix'
z=. '' ; u , v , , t ,&.>/ '';'-',&.>}:u
z=. ((60 80{z),&.>/'-',&.>(11+i.9){z) (70 90+/1+i.9)}z
FR100=: ('soixante et onze';'quatre-vingts') 61 80}z

t=. 2 }. (,&'décillion'@(_9&}.)&.>i{ENU) (i=. 11+i.10)}ENU
FRU=: ('';'mille') , ,(,. ,&'ard'@(_2&}.)&.>) t

fr=: 3 : 0
)

For example:


German

The name in German of a non-negative integer is formed on groups of 3 digits, starting from the right. Each group is suffixed with its name, and a group of three 0-digits is omitted (unless all groups are all 0-digits, in which case the name is "null").

Numbers of the form 10^3*k are named as follows: 10^3 6 9 are tausand, million, and milliarde; and for k>1 , the name for 10^6*k is the Latin for k suffixed by illion and the name for 10^(6*k)+3 is the Latin for k suffixed by illiarde. For example, 10^48 is oktillion, where (10^48) = 10^6*8 and okt is 8 in Latin.

The logic can be implemented as follows:

Work in Progress

u=. <;._1 ' eins zwei drei vier fünf sechs sieben acht neun zehn'
v=. <;._1 ' elf zwölf dreizehn vierzehn fünfzehn sechzehn siebzehn achtzehn neunzehn'
t=. <;._1 ' zwanzig dreißig vierzig fünfzig sechzig siebzig achtzig neunzig'
DE100=: '' ; u , v , , t ,~&.>/ '';('ein';}.}:u),&.><'und'

z=. (;:'m b tr quadr quint sext sept okt non'),&.> <'illion'
u=. ;:'un duo tre quattuor quin sex septen okto novem'
t=. (;:'dez vigint trigint quadragint quinquagint sexagint septuagint octogint nonagint'),&.><'illion'
DEU=: ('';'tausand') , ,(,. ,&'arde'@(_2&}.)&.>) z,(, t ,~&.>/ '';u),<'centillion'

de=: 3 : 0
)

For example:


Chinese

The name in Chinese of a non-negative integer is formed on groups of 4 digits. The groups are named 萬 (10^4), 億 (10^8), and 兆 (10^12). Powers of 10 greater than or equal to 10^16 have no commonly accepted names.

There are two additional idiomatic rules:

a. Internal 0 digits in the leading group, non-trailing 0 digits in non-leading groups, and completely 0 internal groups, are denoted by 零 (zero), but a string of multiple 零 is replaced by a single 零. Thus 9027 is 九千零二十七 (9 thousand oh 2 ten 7), 9007 is 九千零七 (9 thousand oh 7), and 900000567 is 九億零五百六十七 (9 100-million oh 5 hundred 6 ten 7).

b. If the middle 2 digits of a group are 0 1, the 一 (one) is omitted. Thus 171217 is 十七萬一千二百一十七 (ten 7 10-thousand 1 thousand 2 hundred 1 ten 7), 9017 is 九千零十七 (9 thousand oh ten 7), and 17 is 十七 (ten 7).

The logic can be implemented as follows:

ZH10=: 7 u:&.> <;._1 ' 零 一 二 三 四 五 六 七 八 九'  NB. i.10
ZH4 =: 7 u:&.> '千';'百';'十';' '                   NB. 10^3 2 1 0
ZHU =: 7 u:&.> '';'萬';'億';'兆'                    NB. 10^0 4 8 12

zh4=: 4 : 0   NB.  x: 1 iff leading group; y: number < 1e4
 b=. 0<d=. 10 10 10 10#:y
 p=. +./\  b>:x
 s=. +./\. b
 t=. 0 0 1 0*.0 1-:1 2{d
 ' ' -.~ ; ((0=y){.ZH10) , (p*.s) # t}.&.> (d{ZH10) ,&.> b #&.> ZH4
)

zh=: 3 : 0
 d=. 10000&#.^:_1 y
 assert. (0<:y) *. ((=<.)y) *. d <:&# ZHU
 t=. ; (+./\.*d) # (((#d){.1)zh4&.>d) ,&.> (*d)#&.>|.(#d){.ZHU
 z=. >{.ZH10  NB. zero
 ((0=y)#z) , t{~(i.#t)-.,(i.#z)+/(,~z) I.@E. t
)

For example:

   zh 123456789
一億二千三百四十五萬六千七百八十九
   zh 12e12 + 913e8 + 14e4 + 15
十二兆零九百一十三億零十四萬零十五
   zh 12e12 +         14e4 + 15
十二兆零十四萬零十五

   2^53x
9007199254740992
   10000&#.^:_1 ] 2^53
9007 1992 5474 992

   zh 2^53x
九千零七兆一千九百九十二億五千四百七十四萬零九百九十二

Roman

See the Roman Numerals essay.



Contributed by Roger Hui.