· 8 years ago · Jun 29, 2018, 03:52 AM
1(format nil "~r" 1234) ==> "one thousand two hundred thirty-four"
2
3(format nil "~@r" 1234) ==> "MCCXXXIV"
4
5@echo off
6
7set zero_to_nineteen=Zero One Two Three Four Five Six Seven Eight Nine Ten Eleven Twelve Thirteen Fourteen Fifteen Sixteen Seventeen Eighteen Nineteen
8set twenty_to_ninety=ignore ignore Twenty Thirty Forty Fifty Sixty Seventy Eighty Ninety
9set big_numbers=ignore Thousand Million Billion Trillion Quadrillion Quintillion Sextillion Septillion Octillion Nonillion Decillion Undecillion Duodecillion Tredecillion Quattuordecillion Quindecillion Sexdecillion Septendecillion Octodecillion Novemdecillion Vigintillion
10rem 10^0 10^3 10^6 10^9 10^12 10^15 10^18 10^21 10^24 10^27 10^30 10^33 10^36 10^39 10^42 10^45 10^48 10^51 10^54 10^57 10^60 10^63
11
12call :parse_numbers %*
13
14exit /B 0
15
16:parse_numbers
17 :parse_numbers_loop
18 if "$%~1" == "$" goto parse_numbers_end
19 call :parse_number %~1
20 echo %~1 -^> %parse_number_result%
21 shift
22 goto parse_numbers_loop
23 :parse_numbers_end
24 exit /B 0
25
26:parse_number
27 call :get_sign %~1
28 set number_sign=%get_sign_result%
29 call :remove_groups %get_sign_result_number%
30 call :trim_leading_zeros %remove_groups_result%
31 set number=%trim_leading_zeros_result%
32 if "$%number%" == "$0" (
33 set parse_number_result=Zero
34 exit /B 0
35 )
36 set counter=0
37 set parse_number_result=
38 :parse_number_loop
39 set last_three=%number:~-3%
40 set number=%number:~0,-3%
41 call :parse_three %last_three%
42 call :get_from %counter% %big_numbers%
43 if "$%get_from_result%" == "$" (
44 set parse_number_result=* ERR: the number is too big! Even wikipedia doesn't know how it's called!
45 exit /B 0
46 )
47 if not "$%parse_three_result%" == "$Zero" (
48 if %counter% == 0 (
49 set parse_number_result=%parse_three_result%
50 ) else (
51 if not "$%parse_number_result%" == "$" (
52 set parse_number_result=%parse_three_result% %get_from_result% %parse_number_result%
53 ) else (
54 set parse_number_result=%parse_three_result% %get_from_result%
55 )
56 )
57 )
58 set /A counter+=1
59 if not "$%number%" == "$" goto parse_number_loop
60 if "$%parse_number_result%" == "$" (
61 set parse_number_result=Zero
62 exit /B 0
63 ) else if not "$%number_sign%" == "$" (
64 set parse_number_result=%number_sign% %parse_number_result%
65 )
66 exit /B 0
67
68:parse_three
69 call :trim_leading_zeros %~1
70 set three=%trim_leading_zeros_result%
71 set /A three=%three% %% 1000
72 set /A two=%three% %% 100
73 call :parse_two %two%
74 set parse_three_result=
75 set /A digit=%three% / 100
76 if not "$%digit%" == "$0" (
77 call :get_from %digit% %zero_to_nineteen%
78 )
79 if not "$%digit%" == "$0" (
80 if not "$%get_from_result%" == "$Zero" (
81 set parse_three_result=%get_from_result% Hundred
82 )
83 )
84 if "$%parse_two_result%" == "$Zero" (
85 if "$%parse_three_result%" == "$" (
86 set parse_three_result=Zero
87 )
88 ) else (
89 if "$%parse_three_result%" == "$" (
90 set parse_three_result=%parse_two_result%
91 ) else (
92 set parse_three_result=%parse_three_result% %parse_two_result%
93 )
94 )
95 exit /B 0
96
97:parse_two
98 call :trim_leading_zeros %~1
99 set two=%trim_leading_zeros_result%
100 set /A two=%two% %% 100
101 call :get_from %two% %zero_to_nineteen%
102 if not "$%get_from_result%" == "$" (
103 set parse_two_result=%get_from_result%
104 goto parse_two_20_end
105 )
106 set /A digit=%two% %% 10
107 call :get_from %digit% %zero_to_nineteen%
108 set parse_two_result=%get_from_result%
109 set /A digit=%two% / 10
110 call :get_from %digit% %twenty_to_ninety%
111 if not "$%parse_two_result%" == "$Zero" (
112 set parse_two_result=%get_from_result% %parse_two_result%
113 ) else (
114 set parse_two_result=%get_from_result%
115 )
116 goto parse_two_20_end
117 :parse_two_20_end
118 exit /B 0
119
120:get_from
121 call :trim_leading_zeros %~1
122 set idx=%trim_leading_zeros_result%
123 set /A idx=0+%~1
124 shift
125 :get_from_loop
126 if "$%idx%" == "$0" goto get_from_loop_end
127 set /A idx-=1
128 shift
129 goto get_from_loop
130 :get_from_loop_end
131 set get_from_result=%~1
132 exit /B 0
133
134:trim_leading_zeros
135 set str=%~1
136 set trim_leading_zeros_result=
137 :trim_leading_zeros_loop
138 if not "$%str:~0,1%" == "$0" (
139 set trim_leading_zeros_result=%trim_leading_zeros_result%%str%
140 exit /B 0
141 )
142 set str=%str:~1%
143 if not "$%str%" == "$" goto trim_leading_zeros_loop
144 if "$%trim_leading_zeros_result%" == "$" set trim_leading_zeros_result=0
145 exit /B 0
146
147:get_sign
148 set str=%~1
149 set sign=%str:~0,1%
150 set get_sign_result=
151 if "$%sign%" == "$-" (
152 set get_sign_result=Minus
153 set get_sign_result_number=%str:~1%
154 ) else if "$%sign%" == "$+" (
155 set get_sign_result_number=%str:~1%
156 ) else (
157 set get_sign_result_number=%str%
158 )
159 exit /B 0
160
161:remove_groups
162 set str=%~1
163 set remove_groups_result=%str:'=%
164 exit /B 0
165
166@echo off
167rem 10^x:x= 66 63 60 57 54 51 48 45 42 39 36 33 30 27 24 21 18 15 12 9 6 3 0
168call number 0
169call number 2
170call number -17
171call number 30
172call number 48
173call number -256
174call number 500
175call number 874
176call number 1'024
177call number -17'001
178call number 999'999
179call number 1'048'576
180call number -1'000'001'000'000
181call number 912'345'014'587'957'003
182call number -999'912'345'014'587'124'337'999'999
183call number 111'222'333'444'555'666'777'888'999'000'000'000'001
184call number -912'345'014'587'912'345'014'587'124'912'345'014'587'124'337
185call number 999'999'999'999'999'999'999'999'999'999'999'999'999'999'999'999'999'999'999'999'999'999
186call number 1'000'000'000'000'000'000'000'000'000'000'000'000'000'000'000'000'000'000'000'000'000'000
187rem 10^x:x= 66 63 60 57 54 51 48 45 42 39 36 33 30 27 24 21 18 15 12 9 6 3 0
188
1890 -> Zero
1902 -> Two
191-17 -> Minus Seventeen
19230 -> Thirty
19348 -> Forty Eight
194-256 -> Minus Two Hundred Fifty Six
195500 -> Five Hundred
196874 -> Eight Hundred Seventy Four
1971'024 -> One Thousand Twenty Four
198-17'001 -> Minus Seventeen Thousand One
199999'999 -> Nine Hundred Ninety Nine Thousand Nine Hundred Ninety Nine
2001'048'576 -> One Million Forty Eight Thousand Five Hundred Seventy Six
201-1'000'001'000'000 -> Minus One Trillion One Million
202912'345'014'587'957'003 -> Nine Hundred Twelve Quadrillion Three Hundred Forty Five Trillion Fourteen Billion Five Hundred Eighty Seven Million Nine Hundred Fifty Seven Thousand Three
203-999'912'345'014'587'124'337'999'999 -> Minus Nine Hundred Ninety Nine Septillion Nine Hundred Twelve Sextillion Three Hundred Forty Five Quintillion Fourteen Quadrillion Five Hundred Eighty Seven Trillion One Hundred Twenty Four Billion Three Hundred Thirty Seven Million Nine Hundred Ninety Nine Thousand Nine Hundred Ninety Nine
204111'222'333'444'555'666'777'888'999'000'000'000'001 -> One Hundred Eleven Undecillion Two Hundred Twenty Two Decillion Three Hundred Thirty Three Nonillion Four Hundred Forty Four Octillion Five Hundred Fifty Five Septillion Six Hundred Sixty Six Sextillion Seven Hundred Seventy Seven Quintillion Eight Hundred Eighty Eight Quadrillion Nine Hundred Ninety Nine Trillion One
205-912'345'014'587'912'345'014'587'124'912'345'014'587'124'337 -> Minus Nine Hundred Twelve Tredecillion Three Hundred Forty Five Duodecillion Fourteen Undecillion Five Hundred Eighty Seven Decillion Nine Hundred Twelve Nonillion Three Hundred Forty Five Octillion Fourteen Septillion Five Hundred Eighty Seven Sextillion One Hundred Twenty Four Quintillion Nine Hundred Twelve Quadrillion Three Hundred Forty Five Trillion Fourteen Billion Five Hundred Eighty Seven Million One Hundred Twenty Four Thousand Three Hundred Thirty Seven
206999'999'999'999'999'999'999'999'999'999'999'999'999'999'999'999'999'999'999'999'999'999 -> Nine Hundred Ninety Nine Vigintillion Nine Hundred Ninety Nine Novemdecillion Nine Hundred Ninety Nine Octodecillion Nine Hundred Ninety Nine Septendecillion Nine Hundred Ninety Nine Sexdecillion Nine Hundred Ninety Nine Quindecillion Nine Hundred Ninety Nine Quattuordecillion Nine Hundred Ninety Nine Tredecillion Nine Hundred Ninety Nine Duodecillion Nine Hundred Ninety Nine Undecillion Nine Hundred Ninety Nine Decillion Nine Hundred Ninety Nine Nonillion Nine Hundred Ninety Nine Octillion Nine Hundred Ninety Nine Septillion Nine Hundred Ninety Nine Sextillion Nine Hundred Ninety Nine Quintillion Nine Hundred Ninety Nine Quadrillion Nine Hundred Ninety Nine Trillion Nine Hundred Ninety Nine Billion Nine Hundred Ninety Nine Million Nine Hundred Ninety Nine Thousand Nine Hundred Ninety Nine
2071'000'000'000'000'000'000'000'000'000'000'000'000'000'000'000'000'000'000'000'000'000'000 -> * ERR: the number is too big! Even wikipedia doesn't know how it's called!
208
209dd 0ba02c6bfh, 0b8bd10c1h, 0e808b512h, 0ea870100h, 08700e9e8h, 010273eah
210dd 0e0e8c2h, 06b51872h, 0c000ebe8h, 0b3c02e8h, 03368067dh, 0b2e901h
211dd 0baaa5004h, 0fd8110c1h, 0cd7c1630h, 0bf3031bbh, 0a0571000h, 0ec880080h
212dd 0c581c589h, 023c0081h, 0e7f087ch, 0823e38h, 027b00875h, 0e901d068h
213dd 0b6400080h, 04f6f603h, 080d08a1ch, 0b60f80c4h, 07f06c7f4h, 088303000h
214dd 0ac00813eh, 087ef828h, 0b00056e8h, 051e81dh, 0d83850adh, 0e7f157ch
215dd 0a74fc38h, 0262ce088h, 0e901a368h, 01d2c003bh, 0580036e8h, 0b7efc38h
216dd 0774d838h, 0f828e088h, 0800026e8h, 0127e1dfah, 0afd448ah, 0440afe44h
217dd 074f838ffh, 0e8c28a05h, 0cafe000fh, 0ab7cee39h, 05a2405c6h, 021cd09b4h
218dd 05e856c3h, 020b05e00h, 0c5bec3aah, 074c00a02h, 03c80460ah, 0fefa755bh
219dd 046f675c8h, 0745b3cach, 0f8ebaae8h, 0eec1d689h, 08a3c8a03h, 07e180cah
220dd 0cfd2c1feh, 0ebe8c342h, 0fed8d0ffh, 0c3f775cdh, 01e581e8fh, 0303c5ea8h
221dd 0df6f652ah, 078bde03ch, 05e027500h, 01ec1603ch, 07d40793dh, 0603c8080h
222dd 09f6f2838h, 040f17a3dh, 080f17a22h, 0403d7264h, 0793cdee1h, 0140740f1h
223dd 01e2f7d32h, 02f488948h, 0a7c43b05h, 0a257af9bh, 0be297b6ch, 04609e30ah
224dd 0b8f902abh, 07c21e13eh, 09a077d9eh, 054f82ab5h, 0fabe2af3h, 08a6534cdh
225dd 0d32b4c97h, 035c7c8ceh, 082bcc833h, 0f87f154fh, 0650ff7eah, 02f143fdfh
226dd 0a1fd687fh, 0c3e687fdh, 0c6d50fe0h, 075f13574h, 0898c335bh, 0e748ce85h
227dd 08769676fh, 0ad2cedd3h, 0928c77c7h, 077e2d18eh, 01a77e8f6h
228db 0bah, 01bh
229
230mov di,strings
231 mov dx,tree_data * 8 + 1
232 mov bp,code_data * 8
233l1:
234 mov ch,8
235 call extract_bits
236 xchg dx,bp
237 call extract_bit
238 xchg dx,bp
239 jnc l2
240 add dx,ax
241l2:
242 call extract_bit
243 jc l3
244 mov ch,6
245 call extract_bits
246 shr al,2
247 cmp al,11
248 push l27
249 jl get_string
250l25:
251 add al,48+32
252 stosb
253l27:
254 mov dx,tree_data * 8 + 1
255l3:
256 cmp bp,end_data * 8
257 jl l1
258
259convert:
260 mov bx,'01'
261 mov di,01000h
262 push di
263
264 mov al,[80h]
265 mov ah,ch
266 mov bp,ax
267 add bp,81h
268 cmp al,2
269 jl zero
270 jg l90
271 cmp byte ptr [82h],bh
272 jne l90
273zero:
274 mov al,39
275 push done
276
277get_string:
278 mov si,strings-1
279 or al,al
280 je l36
281l35:
282 inc si
283 cmp byte ptr [si],';'+32
284 jne l35
285 dec al
286 jnz l35
287l36:
288 inc si
289l37:
290 lodsb
291 cmp al,';'+32
292 je ret
293 stosb
294 jmp l37
295
296
297l90:
298 inc ax
299 mov dh,3
300 div dh
301 add al,28
302 mov dl,al
303 add ah,80h
304 db 0fh, 0b6h, 0f4h ; movzx si,ah
305 mov word ptr [80h],'00'
306
307l95:
308 lodsb
309
310 sub al,bh
311 jle l100
312 call get_string2
313 mov al,29
314 call get_string2
315
316l100:
317 lodsw
318 push ax
319 cmp al,bl
320 jl l150
321 jg l140
322 cmp ah,bh
323 je l140
324
325 mov al,ah
326 sub al,'0'-10
327 push l150
328
329get_string2:
330 push si
331 call get_string
332 pop si
333 mov al,' '
334 stosb
335 ret
336
337l140:
338 sub al,'0'-19
339 call get_string2
340
341l150:
342 pop ax
343 cmp ah,bh
344 jle l200
345 cmp al,bl
346 je l200
347 mov al,ah
348 sub al,bh
349 call get_string2
350
351l200:
352 cmp dl,29
353 jle l300
354
355 mov al,[si-3]
356 or al,[si-2]
357 or al,[si-1]
358 cmp al,bh
359 je l300
360
361 mov al,dl
362 call get_string2
363
364l300:
365 dec dl
366 cmp si,bp
367 jl l95
368
369done:
370 mov byte ptr [di],'$'
371 pop dx
372 mov ah,9
373 int 21h
374 int 20h
375
376l41:
377 rcr al,1
378 dec ch
379 jz ret
380
381extract_bits:
382 push l41
383extract_bit:
384 mov si,dx
385 shr si,3
386 mov bh,[si]
387 mov cl,dl
388 and cl,7
389 inc cl
390 ror bh,cl
391 inc dx
392 ret
393
394tree_data:
395 dw 01e8fh, 01e58h, 05ea8h, 0303ch, 0652ah, 0df6fh, 0e03ch, 078bdh
396 dw 07500h, 05e02h, 0603ch, 01ec1h, 0793dh, 07d40h, 08080h, 0603ch
397 dw 02838h, 09f6fh, 07a3dh, 040f1h, 07a22h, 080f1h, 07264h, 0403dh
398 dw 0dee1h, 0793ch, 040f1h, 01407h, 07d32h, 01e2fh, 08948h
399 db 048h
400code_data:
401 dw 052fh, 0c43bh, 09ba7h, 057afh, 06ca2h, 0297bh, 0abeh, 09e3h
402 dw 0ab46h, 0f902h, 03eb8h, 021e1h, 09e7ch, 077dh, 0b59ah, 0f82ah
403 dw 0f354h, 0be2ah, 0cdfah, 06534h, 0978ah, 02b4ch, 0ced3h, 0c7c8h
404 dw 03335h, 0bcc8h, 04f82h, 07f15h, 0eaf8h, 0ff7h, 0df65h, 0143fh
405 dw 07f2fh, 0fd68h, 0fda1h, 0e687h, 0e0c3h, 0d50fh, 074c6h, 0f135h
406 dw 05b75h, 08c33h, 08589h, 048ceh, 06fe7h, 06967h, 0d387h, 02cedh
407 dw 0c7adh, 08c77h, 08e92h, 0e2d1h, 0f677h, 077e8h, 0ba1ah
408 db 01bh
409end_data:
410
411strings:
412
413static string wordify(decimal v)
414 {
415 if (v == 0) return "zero";
416 var units = " one two three four five six seven eight nine".Split();
417 var teens = " eleven twelve thir# four# fif# six# seven# eigh# nine#".Replace("#", "teen").Split();
418 var tens = " ten twenty thirty forty fifty sixty seventy eighty ninety".Split();
419 var thou = " thousand m# b# tr# quadr# quint# sext# sept# oct#".Replace("#", "illion").Split();
420 var g = (v < 0) ? "minus " : "";
421 var w = "";
422 var p = 0;
423 v = Math.Abs(v);
424 while (v > 0)
425 {
426 int b = (int)(v % 1000);
427 if (b > 0)
428 {
429 var h = (b / 100);
430 var t = (b - h * 100) / 10;
431 var u = (b - h * 100 - t * 10);
432 var s = ((h > 0) ? units[h] + " hundred" + ((t > 0 | u > 0) ? " and " : "") : "")
433 + ((t > 0) ? (t == 1 && u > 0) ? teens[u] : tens[t] + ((u > 0) ? "-" : "") : "")
434 + ((t != 1) ? units[u] : "");
435 s = (((v > 1000) && (h == 0) && (p == 0)) ? " and " : (v > 1000) ? ", " : "") + s;
436 w = s + " " + thou[p] + w;
437 }
438 v = v / 1000;
439 p++;
440 }
441 return g + w;
442 }
443
444static void Main(string[] args)
445{
446 Console.WriteLine(wordify(decimal.MaxValue));
447}
448
449#include <string>
450using namespace std;
451
452string Thousands[] = { "zero", "thousand", "million", "billion", "trillion", "quadrillion", "quintillion", "sexillion", "septillion", "octillion", "nonillion", "decillion" };
453string Ones[] = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" };
454string Tens[] = { "zero", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety" };
455string concat(bool cond1, string first, bool cond2, string second) { return (cond1 ? first : "") + (cond1 && cond2 ? " " : "") + (cond2 ? second : ""); }
456
457string toStringBelowThousand(unsigned long long n) {
458 return concat(n >= 100, Ones[n / 100] + " hundred", n % 100 != 0, (n % 100 < 20 ? Ones[n % 100] : Tens[(n % 100) / 10] + (n % 10 > 0 ? " " + Ones[n % 10] : "")));
459}
460
461string toString(unsigned long long n, int push = 0) {
462 return n == 0 ? "zero" : concat(n >= 1000, toString(n / 1000, push + 1), n % 1000 != 0, concat(true, toStringBelowThousand(n % 1000), push > 0, Thousands[push]));
463}
464
465cout << toString(51351); // => fifty one thousand three hundred fifty one
466
467perl -MNumber::Spell -e 'print spell_number(2);'
468
469w=lambda n:_(n,["","thousand "]+p("m b tr quadr quint","illion"))[:-1]or"zero"
470_=lambda n,S:n*"x"and _(n//M,S[1:])+(Z[n%M//C]+"hundred ")*(n%M//C>0)+(n%C>19
471and p("twen thir fo"+R,"ty")[n%C//10-2]+Z[n%10]or Z[n%C])+S[0]*(n%M>0)
472p=lambda a,b="":[i+b+" "for i in a.split()]
473R="r fif six seven eigh nine"
474M=1000
475C=100
476Z=[""]+p("one two three four five%st nine ten eleven twelve"%R[5:20])+p(
477"thir fou"+R,"teen")
478
479if __name__ == "__main__":
480 import sys
481 assert(w(0)=="zero")
482 assert(w(100)=="one hundred")
483 assert(w(1000000)=="one million")
484 assert(w(1024)=="one thousand twenty four")
485 assert(w(1048576)=="one million forty eight thousand five hundred seventy six")
486
487w=lambda n:["zero"," ".join(_(n,0))][n>0]
488_=lambda n,l:_(n//M,l+1)+[E,Z[n%M//C]+["hundred"]][n%M//C>0]+
489(p("twen thir fo"+R,"ty")[n%C//10-2]+Z[n%10]if n%C>19 else Z[n%C])+
490[E,([E,["thousand"]]+p("m b tr quadr quint","illion"))[l]][n%M>0]if n else E
491p=lambda a,b:[[i+b]for i in a.split()]
492E=[];R="r fif six seven eigh nine";M=1000;C=100
493Z=[E]+p("one two three four five six seven eight nine ten eleven twelve","")+
494p("thir fou"+R,"teen")
495
496if __name__ == "__main__":
497 import sys
498 print w(int(sys.argv[1]))
499 assert(w(100)=="one hundred")
500 assert(w(1000000)=="one million")
501 assert(w(1024)=="one thousand twenty four")
502 assert(w(1048576)=="one million forty eight thousand five hundred seventy six")
503
504g=lambda n:["zero"," ".join(w(n,0))][n>0]
505w=lambda n,l:w(n//m,l+1)+[e,z[n%m//100]+["hundred"]][n%m//100>0]+
506(p("twen thir fo"+r,"ty")[n%100//10-2]+z[n%10]if n%100>19 else z[n%100])+
507[e,k[l]][n%m>0]if n else e
508p=lambda a,b:[[i+b]for i in a.split()]
509e=[];r="r fif six seven eigh nine";m=1000
510k=[e,["thousand"]]+p("m b tr quadr quint","illion")
511z=[e]+p("one two three four five six seven eight nine ten eleven twelve","")+
512p("thir fou"+r,"teen")
513
514>>> n2w(2**20)
515'one million forty-eight thousand five hundred seventy-six'
516
517def n2w(n):
518 if n < 0: return 'minus ' + n2w(-n)
519 if n < 10: return W('zero one two three four five six seven eight nine')[n]
520 if n < 20: return W('ten eleven twelve',
521 'thir four fif six seven eigh nine',
522 'teen')[n-10]
523 if n < 100:
524 tens = W('', 'twen thir for fif six seven eigh nine', 'ty')[n//10-2]
525 return abut(tens, '-', n2w(n % 10))
526 if n < 1000:
527 return combine(n, 100, 'hundred')
528 for i, word in enumerate(W('thousand', 'm b tr quadr quint', 'illion')):
529 if n < 10**(3*(i+2)):
530 return combine(n, 10**(3*(i+1)), word)
531 assert False
532
533def W(b, s='', suff=''): return b.split() + [s1 + suff for s1 in s.split()]
534def combine(n, m, term): return abut(n2w(n // m) + ' ' + term, ' ', n2w(n % m))
535def abut(w10, sep, w1): return w10 if w1 == 'zero' else w10 + sep + w1
536
537#light
538let thou=[|"";"thousand";"million";"billion";"trillion";"quadrillion";"quintillion"|]
539let ones=[|"";"one";"two";"three";"four";"five";"six";"seven";"eight";"nine";"ten";"eleven";
540 "twelve";"thirteen";"fourteen";"fifteen";"sixteen";"seventeen";"eighteen";"nineteen"|]
541let tens=[|"";"";"twenty";"thirty";"forty";"fifty";"sixty";"seventy";"eighty";"ninety"|]
542let (^-) x y = if y="" then x else x^"-"^y
543let (^+) x y = if y="" then x else x^" "^y
544let (^?) x y = if x="" then x else x^+y
545let (+^+) x y = if x="" then y else x^+y
546let Tiny n = if n < 20 then ones.[n] else tens.[n/10] ^- ones.[n%10]
547let Small n = (ones.[n/100] ^? "hundred") +^+ Tiny(n%100)
548let rec Big n t = if n = 0UL then "" else
549 (Big (n/1000UL) (t+1)) +^+ (Small(n%1000UL|>int) ^? thou.[t])
550let Convert n = if n = 0UL then "zero" else Big n 0
551
552let Show n =
553 printfn "%20u -> "%s"" n (Convert n)
554
555let tinyTests = [0; 1; 10; 11; 19; 20; 21; 30; 99] |> List.map uint64
556let smallTests = tinyTests @ (tinyTests |> List.map (fun n -> n + 200UL))
557let MakeTests t1 t2 =
558 List.map (fun n -> n * (pown 1000UL t1)) smallTests
559 |> List.map_concat (fun n -> List.map (fun x -> x * (pown 1000UL t2) + n) smallTests)
560for n in smallTests do
561 Show n
562for n in MakeTests 1 0 do
563 Show n
564for n in MakeTests 5 2 do
565 Show n
566Show 1000001000678000001UL
567Show 17999999999999999999UL
568
569if exists (select 1 from sys.objects where object_id = object_id(N'dbo.fnGetNumberString'))
570 drop function fnGetNumberString
571go
572
573/*
574Tests:
575declare @tests table ( testValue bigint )
576insert into @tests select -43213 union select -5 union select 0 union select 2 union select 15 union select 33 union select 100 union select 456 union select 1024 union select 10343 union select 12345678901234 union select -3434343434343
577
578select testValue, dbo.fnGetNumberString(testValue) as textValue
579from @tests
580*/
581
582create function dbo.fnGetNumberString
583(
584 @value bigint
585)
586returns nvarchar(1024)
587as
588begin
589 if @value = 0 return 'zero' -- lets me avoid special-casing this later
590
591 declare @isNegative bit
592 set @isNegative = 0
593
594 if @value < 0
595 select @isNegative = 1, @value = @value * -1
596
597 declare @groupNames table ( groupOrder int, groupName nvarchar(15) )
598 insert into @groupNames select 1, '' union select 2, 'thousand' union select 3, 'million' union select 4, 'billion' union select 5, 'trillion' union select 6, 'quadrillion' union select 7, 'quintillion' union select 8, 'sextillion'
599
600 declare @digitNames table ( digit tinyint, digitName nvarchar(10) )
601 insert into @digitNames select 0, '' union select 1, 'one' union select 2, 'two' union select 3, 'three' union select 4, 'four' union select 5, 'five' union select 6, 'six' union select 7, 'seven' union select 8, 'eight' union select 9, 'nine' union select 10, 'ten' union select 11, 'eleven' union select 12, 'twelve' union select 13, 'thirteen' union select 14, 'fourteen' union select 15, 'fifteen' union select 16, 'sixteen' union select 17, 'seventeen' union select 18, 'eighteen' union select 19, 'nineteen'
602
603 declare @tensGroups table ( digit tinyint, groupName nvarchar(10) )
604 insert into @tensGroups select 2, 'twenty' union select 3, 'thirty' union select 4, 'forty' union select 5, 'fifty' union select 6, 'sixty' union select 7, 'seventy' union select 8, 'eighty' union select 9, 'ninety'
605
606 declare @groups table ( groupOrder int identity, groupValue int )
607
608 declare @convertedValue varchar(50)
609
610 while @value > 0
611 begin
612 insert into @groups (groupValue) select @value % 1000
613
614 set @value = @value / 1000
615 end
616
617 declare @returnValue nvarchar(1024)
618 set @returnValue = ''
619
620 if @isNegative = 1 set @returnValue = 'negative'
621
622 select @returnValue = @returnValue +
623 case when len(h.digitName) > 0 then ' ' + h.digitName + ' hundred' else '' end +
624 case when len(isnull(t.groupName, '')) > 0 then ' ' + t.groupName + case when len(isnull(o.digitName, '')) > 0 then '-' else '' end + isnull(o.digitName, '') else case when len(isnull(o.digitName, '')) > 0 then ' ' + o.digitName else '' end end +
625 case when len(n.groupName) > 0 then ' ' + n.groupName else '' end
626 from @groups g
627 join @groupNames n on n.groupOrder = g.groupOrder
628 join @digitNames h on h.digit = (g.groupValue / 100)
629 left join @tensGroups t on t.digit = ((g.groupValue % 100) / 10)
630 left join @digitNames o on o.digit = case when (g.groupValue % 100) < 20 then g.groupValue % 100 else g.groupValue % 10 end
631 order by g.groupOrder desc
632
633 return @returnValue
634end
635go
636
637NumSpeller.spell(458582)
638
639NumSpeller.spell(458582)
640
641#include <stdio.h>
642#include <string.h>
643
644const char *zero_to_nineteen[20] = {"", "One ", "Two ", "Three ", "Four ", "Five ", "Six ", "Seven ", "Eight ", "Nine ", "Ten ", "Eleven ", "Twelve ", "Thirteen ", "Fourteen ", "Fifteen ", "Sixteen ", "Seventeen ", "Eighteen ", "Nineteen "};
645
646const char *twenty_to_ninety[8] = {"Twenty ", "Thirty ", "Forty ", "Fifty ", "Sixty ", "Seventy ", "Eighty ", "Ninety "};
647
648const char *big_numbers[7] = {"", "Thousand ", "Million ", "Billion ", "Trillion ", "Quadrillion ", "Quintillion "};
649
650void num_to_word(char *buf, unsigned long long num)
651{
652 unsigned long long power_of_1000 = 1000000000000000000ull;
653 int power_index = 6;
654
655 if(num == 0)
656 {
657 strcpy(buf, "Zero");
658 return;
659 }
660
661 buf[0] = 0;
662
663 while(power_of_1000 > 0)
664 {
665 int group = num / power_of_1000;
666 if(group >= 100)
667 {
668 strcat(buf, zero_to_nineteen[group / 100]);
669 strcat(buf, "Hundred ");
670 group %= 100;
671 }
672
673 if(group >= 20)
674 {
675 strcat(buf, twenty_to_ninety[group / 10 - 2]);
676 group %= 10;
677 }
678
679 if(group > 0)
680 strcat(buf, zero_to_nineteen[group]);
681
682 if(num >= power_of_1000)
683 strcat(buf, big_numbers[power_index]);
684
685 num %= power_of_1000;
686 power_of_1000 /= 1000;
687 power_index--;
688 }
689
690 buf[strlen(buf) - 1] = 0;
691}
692
693#include <string.h>
694#define C strcat(b,
695#define U unsigned long long
696char*z[]={"","One","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Eleven","Twelve","Thirteen","Fourteen","Fifteen","Sixteen","Seventeen","Eighteen","Nineteen"},*t[]={"Twenty ","Thirty ","Forty ","Fifty ","Sixty ","Seventy ","Eighty ","Ninety "},*q[]={"","Thousand ","Million ","Billion ","Trillion ","Quadrillion ","Quintillion "};
697void W(char*b,U n){U p=1000000000000000000ull;int i=6;*b=0;if(!n)strcpy(b,"Zero ");else while(p){int g=n/p;if(g>99){C z[g/100]);C " ");C "Hundred ");g%=100;}if(g>19){C t[g/10-2]);g%=10;}if(g)C z[g]),C " ");if(n>=p)C q[i]);n%=p;p/=1000;i--;}b[strlen(b)-1]=0;}
698
699my %expo=(0,'',
700 qw'1 thousand 2 million 3 billion 4 trillion 5 quadrillion 6 quintillion
701 7 sextillion 8 septillion 9 octillion 10 nonillion 11 decillion 12 undecillion
702 13 duodecillion 14 tredecillion 15 quattuordecillion 16 quindecillion
703 17 sexdecillion 18 septendecillion 19 octodecillion 20 novemdecillion
704 21 vigintillion'
705);
706
707my %digit=(0,'',
708 qw'1 one 2 two 3 three 4 four 5 five 6 six 7 seven 8 eight 9 nine 10 ten
709 11 eleven 12 twelve 13 thirteen 14 fourteen 15 fifteen 16 sixteen 17 seventeen
710 18 eighteen 19 nineteen 2* twenty 3* thirty 4* forty 5* fifty 6* sixty
711 7* seventy 8* eighty 9* ninety'
712);
713
714sub spell_number(_){
715 local($_)=@_;
716 ($_,@_)=split/(?=(?:.{3})*+$)/;
717 $_=0 x(3-length).$_;
718 unshift@_,$_;
719 my @o;
720 my $c=@_;
721 for(@_){
722 my $o='';
723 /(.)(.)(.)/;
724 $o.=$1?$digit{$1}.' hundred':'';
725 $o.=$2==1?
726 ' '.$digit{$2.$3}
727 :
728 ($2?' '.$digit{"$2*"}:'').
729 ($2&&$3?' ':'').
730 $digit{$3}
731 ;
732 $o.=--$c?($o?' '.$expo{$c}.', ':''):'';
733 push@o,$o;
734 }
735 my $o;
736 $o.=$_ for@o;
737 $o=~/^s*+(.*?)(, )?$/;
738 $o?$1:'zero';
739}
740
741string Number(ulong i)
742{
743 static string[] names = [
744 ""[],
745 " thousand",
746 " million",
747 " billion",
748 " trillion",
749 " quadrillion",
750 ];
751 string ret = null;
752 foreach(mult; names)
753 {
754 if(i%1000 != 0)
755 {
756 if(ret != null) ret = ret ~ ", "
757 ret = Cent(i%1000) ~ mult ~ ret;
758 }
759 i /= 1000;
760 }
761 return ret;
762}
763
764string Cent(int i)
765{
766 static string[] v =
767 [""[], "one", "two", "three", "four",
768 "five", "six", "seven", "eight", "nine"];
769
770 static string[] tens =
771 ["!"[], "!", "twenty", "thirty", "forty",
772 "fifty", "sixty", "seventy", "eighty", "ninety"];
773
774 string p1, p2, p3 = "";
775
776
777 if(i >= 100)
778 {
779 p1 = v[i/100] ~ " hundred";
780 p3 = (i % 100 != 0) ? " and " : ""; //optional
781 }
782 else
783 p1 = "";
784
785 i %= 100;
786 switch(i)
787 {
788 case 0, 1, 2, 3, 4, 5, 6, 7, 8, 9:
789 p2 = v[i];
790 break;
791
792 case 10: p2 = "ten"; break;
793 case 11: p2 = "eleven"; break;
794 case 12: p2 = "twelve"; break;
795 case 13: p2 = "thirteen"; break;
796 case 14: p2 = "fourteen"; break;
797 case 15: p2 = "fifteen"; break;
798 case 16: p2 = "sixteen"; break;
799 case 17: p2 = "seventeen"; break;
800 case 18: p2 = "eighteen"; break;
801 case 19: p2 = "nineteen"; break;
802
803 default:
804 p2 = tens[i/10] ~ "-" ~ v[i%10];
805 break;
806
807 }
808
809 return p1 ~ p3 ~ p2;
810}
811
812import std.stdio;
813void main()
814{
815 writef("%sn", Number(8_000_400_213));
816}
817
818#!/usr/bin/env perl
819my %symbols = (
8201 => "One", 2 => "Two", 3 => "Three", 4 => "Four", 5 => "Five",
8216 => "Six", 7 => "Seven", 8 => "Eight", 9 => "Nine", 10 => "Ten",
82211 => "Eleven", 12 => "Twelve", 13 => "Thirteen", 14 => "Fourteen",
82315 => "Fifteen", 16 => "Sixteen", 17 => "Seventeen", 18 => "Eighteen",
82419 => "Nineteen", 20 => "Twenty", 30 => "Thirty", 40 => "Forty",
82550 => "Fifty", 60 => "Sixty", 70 => "Seventy", 80 => "Eighty",
82690 => "Ninety", 100 => "Hundred");
827
828my %three_symbols = (1 => "Thousand", 2 => "Million", 3 => "Billion" );
829
830sub babo {
831my ($input) = @_;
832my @threes = split(undef, $input);
833my $counter = ($#threes + 1);
834my $remainder = $counter % 3;
835my @result;
836
837while ($counter > 0){
838 my $digits = "";
839 my $three;
840 my $full_match = 0;
841
842 if ($remainder > 0){
843 while ($remainder > 0) {
844 $digits .= shift(@threes);
845 $remainder--;
846 $counter--;
847 }
848 }
849 else {
850 $digits = join('',@threes[0,1,2]);
851 splice(@threes, 0, 3);
852 $counter -= 3;
853 }
854 if (exists($symbols{$digits})){
855 $three = $symbols{$digits};
856 $full_match = 1;
857 }
858 elsif (length($digits) == 3) {
859 $three = $symbols{substr($digits,0,1)};
860 $three .= " Hundred";
861 $digits = substr($digits,1,2);
862 if (exists($symbols{$digits})){
863 $three .= " " . $symbols{$digits};
864 $full_match = 1;
865 }
866 }
867 if ($full_match == 0){
868 $three .= " " . $symbols{substr($digits,0,1)."0"};
869 $three .= " " . $symbols{substr($digits,1,1)};
870 }
871 push(@result, $three);
872 if ($counter > 0){
873 push(@result, "Thousand");
874 }
875}
876my $three_counter = 0;
877my @r = map {$_ eq "Thousand" ? $three_symbols{++$three_counter}:$_ }
878 reverse @result;
879return join(" ", reverse @r);
880}
881print babo(1) . "n";
882print babo(12) . "n";
883print babo(120) . "n";
884print babo(1234) . "n";
885print babo(12345) . "n";
886print babo(123456) . "n";
887print babo(1234567) . "n";
888print babo(1234567890) . "n";
889
890function convert_number($number)
891{
892 if (($number < 0) || ($number > 999999999))
893 {
894 throw new Exception("Number is out of range");
895 }
896
897 $Gn = floor($number / 1000000); /* Millions (giga) */
898 $number -= $Gn * 1000000;
899 $kn = floor($number / 1000); /* Thousands (kilo) */
900 $number -= $kn * 1000;
901 $Hn = floor($number / 100); /* Hundreds (hecto) */
902 $number -= $Hn * 100;
903 $Dn = floor($number / 10); /* Tens (deca) */
904 $n = $number % 10; /* Ones */
905
906 $res = "";
907
908 if ($Gn)
909 {
910 $res .= convert_number($Gn) . " Million";
911 }
912
913 if ($kn)
914 {
915 $res .= (empty($res) ? "" : " ") .
916 convert_number($kn) . " Thousand";
917 }
918
919 if ($Hn)
920 {
921 $res .= (empty($res) ? "" : " ") .
922 convert_number($Hn) . " Hundred";
923 }
924
925 $ones = array("", "One", "Two", "Three", "Four", "Five", "Six",
926 "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen",
927 "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eightteen",
928 "Nineteen");
929 $tens = array("", "", "Twenty", "Thirty", "Fourty", "Fifty", "Sixty",
930 "Seventy", "Eigthy", "Ninety");
931
932 if ($Dn || $n)
933 {
934 if (!empty($res))
935 {
936 $res .= " and ";
937 }
938
939 if ($Dn < 2)
940 {
941 $res .= $ones[$Dn * 10 + $n];
942 }
943 else
944 {
945 $res .= $tens[$Dn];
946
947 if ($n)
948 {
949 $res .= "-" . $ones[$n];
950 }
951 }
952 }
953
954 if (empty($res))
955 {
956 $res = "zero";
957 }
958
959 return $res;
960}
961
962#!/usr/bin/perl
963
964use strict;
965use warnings;
966
967use Lingua::EN::Numbers qw(num2en);
968
969print num2en($_), "n" for 2, 1024, 1024*1024;
970
971public abstract class ValueSource
972{
973 public abstract object Value { get; }
974}
975
976public abstract class ValueSource
977{
978 public abstract object Value { get; }
979}
980
981public abstract class NumberTextValueSource:ValueSource
982{
983 public abstract decimal Number { get; }
984 public abstract string Format { get; }
985 public abstract string Negative { get; }
986 public abstract bool UseValueIfZero { get; }
987 public abstract string N0 { get; }
988 public abstract string N1 { get; }
989 public abstract string N2 { get; }
990 public abstract string N3 { get; }
991 public abstract string N4 { get; }
992 public abstract string N5 { get; }
993 public abstract string N6 { get; }
994 public abstract string N7 { get; }
995 public abstract string N8 { get; }
996 public abstract string N9 { get; }
997 public abstract string N10 { get; }
998 public abstract string N11 { get; }
999 public abstract string N12 { get; }
1000 public abstract string N13 { get; }
1001 public abstract string N14 { get; }
1002 public abstract string N15 { get; }
1003 public abstract string N16 { get; }
1004 public abstract string N17 { get; }
1005 public abstract string N18 { get; }
1006 public abstract string N19 { get; }
1007 public abstract string N20 { get; }
1008 public abstract string N30 { get; }
1009 public abstract string N40 { get; }
1010 public abstract string N50 { get; }
1011 public abstract string N60 { get; }
1012 public abstract string N70 { get; }
1013 public abstract string N80 { get; }
1014 public abstract string N90 { get; }
1015 public abstract string N100 { get; }
1016 public abstract string NHundred { get; }
1017 public abstract string N1000 { get; }
1018 public abstract string NThousand { get; }
1019 public abstract string NMillion { get; }
1020 public abstract string NBillion { get; }
1021 public abstract string NTrillion { get; }
1022 public abstract string NQuadrillion { get; }
1023
1024
1025 string getOne(Type t, string v)
1026 {
1027 if (v[0] == '0' && !UseValueIfZero)
1028 return "";
1029 return (string)t.GetProperty("N" + v[0].ToString()).GetValue(this, null);
1030 }
1031 string getTwo(Type t, string v)
1032 {
1033 if (v[0] == '0')
1034 if (v[1] != '0')
1035 return getOne(t, v.Substring(1));
1036 else
1037 return "";
1038
1039 if (v[1] == '0' || v[0] == '1')
1040 return (string)t.GetProperty("N" + v).GetValue(this, null);
1041
1042 return (string)t.GetProperty("N" + v[0].ToString() + "0").GetValue(this, null) +
1043 getOne(t, v.Substring(1));
1044 }
1045 string getThree(Type t, string v)
1046 {
1047 if(v[0] == '0')
1048 return getTwo(t,v.Substring(1));
1049
1050 if (v[0] == '1')
1051 return
1052 N100 +
1053 getTwo(t, v.Substring(1));
1054 return
1055 getOne(t, v[0].ToString()) +
1056 NHundred +
1057 getTwo(t, v.Substring(1));
1058 }
1059 string getFour(Type t, string v)
1060 {
1061 if (v[0] == '0')
1062 return getThree(t, v.Substring(1));
1063 if (v[0] == '1')
1064 return
1065 N1000 +
1066 getThree(t, v.Substring(1));
1067 return
1068 getOne(t, v[0].ToString()) +
1069 NThousand +
1070 getThree(t, v.Substring(1));
1071 }
1072 string getFive(Type t, string v)
1073 {
1074 if (v[0] == '0')
1075 return getFour(t, v.Substring(1));
1076 return
1077 getTwo(t, v.Substring(0, 2)) +
1078 NThousand +
1079 getThree(t, v.Substring(2));
1080 }
1081 string getSix(Type t, string v)
1082 {
1083 if (v[0] == '0')
1084 return getFive(t, v.Substring(1));
1085 return
1086 getThree(t, v.Substring(0, 3)) +
1087 NThousand +
1088 getThree(t, v.Substring(3));
1089 }
1090 string getSeven(Type t, string v)
1091 {
1092 if (v[0] == '0')
1093 return getSix(t, v.Substring(1));
1094 return
1095 getOne(t, v[0].ToString()) +
1096 NMillion +
1097 getSix(t, v.Substring(3));
1098 }
1099 string getEight(Type t, string v)
1100 {
1101 if (v[0] == '0')
1102 return getSeven(t, v.Substring(1));
1103 return
1104 getTwo(t, v.Substring(0, 2)) +
1105 NMillion +
1106 getSix(t, v.Substring(2));
1107 }
1108 string getNine(Type t, string v)
1109 {
1110 if (v[0] == '0')
1111 return getEight(t, v.Substring(1));
1112 return
1113 getThree(t, v.Substring(0, 3)) +
1114 NMillion +
1115 getSix(t, v.Substring(3));
1116 }
1117 string getTen(Type t, string v)
1118 {
1119 if (v[0] == '0')
1120 return getNine(t, v.Substring(1));
1121 return
1122 getOne(t, v.Substring(0, 1)) +
1123 NBillion +
1124 getNine(t, v.Substring(1));
1125 }
1126 string getEleven(Type t, string v)
1127 {
1128 if (v[0] == '0')
1129 return getTen(t, v.Substring(1));
1130 return
1131 getTwo(t, v.Substring(0, 2)) +
1132 NBillion +
1133 getNine(t, v.Substring(2));
1134 }
1135 string getTwelve(Type t, string v)
1136 {
1137 if (v[0] == '0')
1138 return getEleven(t, v.Substring(1));
1139 return
1140 getThree(t, v.Substring(0, 3)) +
1141 NBillion +
1142 getNine(t, v.Substring(3));
1143 }
1144 string getThirteen(Type t, string v)
1145 {
1146 if (v[0] == '0')
1147 return getTwelve(t, v.Substring(1));
1148 return
1149 getOne(t, v.Substring(0, 1)) +
1150 NTrillion +
1151 getTwelve(t, v.Substring(1));
1152 }
1153 string getForteen(Type t, string v)
1154 {
1155 if (v[0] == '0')
1156 return getThirteen(t, v.Substring(1));
1157 return
1158 getTwo(t, v.Substring(0, 2)) +
1159 NTrillion +
1160 getTwelve(t, v.Substring(2));
1161 }
1162 string getFifteen(Type t, string v)
1163 {
1164 if (v[0] == '0')
1165 return getForteen(t, v.Substring(1));
1166 return
1167 getThree(t, v.Substring(0, 3)) +
1168 NTrillion +
1169 getTwelve(t, v.Substring(3));
1170 }
1171 string getSixteen(Type t, string v)
1172 {
1173 if (v[0] == '0')
1174 return getFifteen(t, v.Substring(1));
1175 return
1176 getOne(t, v.Substring(0, 1)) +
1177 NQuadrillion +
1178 getFifteen(t, v.Substring(1));
1179 }
1180 string getSeventeen(Type t, string v)
1181 {
1182 if (v[0] == '0')
1183 return getSixteen(t, v.Substring(1));
1184 return
1185 getTwo(t, v.Substring(0, 2)) +
1186 NQuadrillion +
1187 getFifteen(t, v.Substring(2));
1188 }
1189 string getEighteen(Type t, string v)
1190 {
1191 if (v[0] == '0')
1192 return getSeventeen(t, v.Substring(1));
1193 return
1194 getThree(t, v.Substring(0, 3)) +
1195 NQuadrillion +
1196 getFifteen(t, v.Substring(3));
1197 }
1198 string convert(Type t, string hp)
1199 {
1200 switch (hp.Length)
1201 {
1202 case 1:
1203 return getOne(t, hp);
1204 case 2:
1205 return getTwo(t, hp);
1206 case 3:
1207 return getThree(t, hp);
1208 case 4:
1209 return getFour(t, hp);
1210 case 5:
1211 return getFive(t, hp);
1212 case 6:
1213 return getSix(t, hp);
1214 case 7:
1215 return getSeven(t, hp);
1216 case 8:
1217 return getEight(t, hp);
1218 case 9:
1219 return getNine(t, hp);
1220 case 10:
1221 return getTen(t, hp);
1222 case 11:
1223 return getEleven(t, hp);
1224 case 12:
1225 return getTwelve(t, hp);
1226 case 13:
1227 return getThirteen(t, hp);
1228 case 14:
1229 return getForteen(t, hp);
1230 case 15:
1231 return getFifteen(t, hp);
1232 case 16:
1233 return getSixteen(t, hp);
1234 case 17:
1235 return getSeventeen(t, hp);
1236 case 18:
1237 return getEighteen(t, hp);
1238 }
1239 return "";
1240 }
1241 public override object Value
1242 {
1243 get
1244 {
1245 decimal d = Number;
1246 decimal highPoint, lowPoint;
1247 bool isNeg = d < 0;
1248 d = Math.Abs(d);
1249 highPoint = Math.Floor(d);
1250 lowPoint = d - highPoint;
1251 Type t = this.GetType();
1252
1253 string strHigh = convert(t, highPoint.ToString()),
1254 strLow =
1255 lowPoint > 0 ?
1256 convert(t, lowPoint.ToString().Substring(2)) :
1257 UseValueIfZero ? N0 : "";
1258 if (isNeg) strHigh = Negative + " " + strHigh;
1259 return string.Format(Format, strHigh, strLow);
1260 }
1261 }
1262}
1263
1264public class TRYNumberTextValueSource:NumberTextValueSource
1265{
1266 decimal num;
1267 public TRYNumberTextValueSource(decimal value)
1268 {
1269 num = Math.Round(value, 2);
1270 }
1271 public override decimal Number
1272 {
1273 get { return num; }
1274 }
1275
1276 public override string Format
1277 {
1278 get
1279 {
1280 if (num == 0)
1281 return N0 + " YTL";
1282 if (num > -1 && num < 1)
1283 return "{0}{1} KuruÅŸ";
1284 return "{0} YTL {1} KuruÅŸ";
1285 }
1286 }
1287
1288 public override string Negative
1289 {
1290 get { return "-"; }
1291 }
1292
1293 public override bool UseValueIfZero
1294 {
1295 get { return false; }
1296 }
1297
1298 public override string N0
1299 {
1300 get { return "sıfır"; }
1301 }
1302
1303 public override string N1
1304 {
1305 get { return "bir"; }
1306 }
1307
1308 public override string N2
1309 {
1310 get { return "iki"; }
1311 }
1312
1313 public override string N3
1314 {
1315 get { return "üç"; }
1316 }
1317
1318 public override string N4
1319 {
1320 get { return "dört"; }
1321 }
1322
1323 public override string N5
1324 {
1325 get { return "beÅŸ"; }
1326 }
1327
1328 public override string N6
1329 {
1330 get { return "altı"; }
1331 }
1332
1333 public override string N7
1334 {
1335 get { return "yedi"; }
1336 }
1337
1338 public override string N8
1339 {
1340 get { return "sekiz"; }
1341 }
1342
1343 public override string N9
1344 {
1345 get { return "dokuz"; }
1346 }
1347
1348 public override string N10
1349 {
1350 get { return "on"; }
1351 }
1352
1353 public override string N11
1354 {
1355 get { return "onbir"; }
1356 }
1357
1358 public override string N12
1359 {
1360 get { return "oniki"; }
1361 }
1362
1363 public override string N13
1364 {
1365 get { return "onüç"; }
1366 }
1367
1368 public override string N14
1369 {
1370 get { return "ondört"; }
1371 }
1372
1373 public override string N15
1374 {
1375 get { return "onbeÅŸ"; }
1376 }
1377
1378 public override string N16
1379 {
1380 get { return "onaltı"; }
1381 }
1382
1383 public override string N17
1384 {
1385 get { return "onyedi"; }
1386 }
1387
1388 public override string N18
1389 {
1390 get { return "onsekiz"; }
1391 }
1392
1393 public override string N19
1394 {
1395 get { return "ondokuz"; }
1396 }
1397
1398 public override string N20
1399 {
1400 get { return "yirmi"; }
1401 }
1402
1403 public override string N30
1404 {
1405 get { return "otuz"; }
1406 }
1407
1408 public override string N40
1409 {
1410 get { return "kırk"; }
1411 }
1412
1413 public override string N50
1414 {
1415 get { return "elli"; }
1416 }
1417
1418 public override string N60
1419 {
1420 get { return "altmış"; }
1421 }
1422
1423 public override string N70
1424 {
1425 get { return "yetmiÅŸ"; }
1426 }
1427
1428 public override string N80
1429 {
1430 get { return "seksen"; }
1431 }
1432
1433 public override string N90
1434 {
1435 get { return "doksan"; }
1436 }
1437
1438 public override string N100
1439 {
1440 get { return "yüz"; }
1441 }
1442
1443 public override string NHundred
1444 {
1445 get { return "yüz"; }
1446 }
1447
1448 public override string N1000
1449 {
1450 get { return "bin"; }
1451 }
1452
1453 public override string NThousand
1454 {
1455 get { return "bin"; }
1456 }
1457
1458 public override string NMillion
1459 {
1460 get { return "milyon"; }
1461 }
1462
1463 public override string NBillion
1464 {
1465 get { return "milyar"; }
1466 }
1467
1468 public override string NTrillion
1469 {
1470 get { return "trilyon"; }
1471 }
1472
1473 public override string NQuadrillion
1474 {
1475 get { return "trilyar"; }
1476 }
1477}