Comment On get_words_from_a_number_which_is_passed_as_a_perimeter_into_this_function

"As part of my new role for a software development firm," writes David Mayer, "I was assigned to sift through some code looking for bugs in the dictionary and spellchecking system. That's how I came across a function called get_words_from_a_number_which_is_passed_as_a_perimeter_into_this_function." [expand full text]
« PrevPage 1 | Page 2 | Page 3 | Page 4 | Page 5Next »

Re: get_words_from_a_number_which_is_passed_as_a_perimeter_into_this_function

2012-04-17 13:07 • by Nagesh
379335 in reply to 379320
Nagesh fake:
RS:
Hey Nagesh is not the only one guilty of butchering the English language. I work with many WASPs and their use of the English language is not much better.

Not understand. Wasp is insect meking nest in corner of my ofice. We are not being able to kil this leving creatures, even though I am geting stinged daily. :(


WASP do not bite, faker!

Re: get_words_from_a_number_which_is_passed_as_a_perimeter_into_this_function

2012-04-17 13:12 • by Nagesh
379336 in reply to 379330
Nagesh:
Nagesh:
geoffrey is plain pagal - (crazy).

java has created more value for business. java is not restricted to just business apps, but also used inside your car, your camera, your phone, your alarm clock and everywhere you can care to think of.

So geoffrey is failing in providing any true picture of world.

Here in Hyderabad, we use chicken for alarum clock.


You must stay in slum outside Charminar. I am in Banjara Hills, madarchod!

Re: get_words_from_a_number_which_is_passed_as_a_perimeter_into_this_function

2012-04-17 13:18 • by Ben Jammin (unregistered)
379337 in reply to 379334
frits:
A 'Brit':
The British tic of critiquing American English is one of the many reasons I loathe British people on the internet.


The American tic of loathing the English defending their language (notice that the Scots, Welsh and Irish won't defend it); and getting confused between Britain and the coutries that make it, is one of the many reasons I loathe Armerican people on the internet.

The opinions of folks from a fallen empire which has shrunken to the size of the Philadelphia metro area do not interest me.


Language is meant to communicate ideas. If those on the receiving end can interpret the original idea, then success.

"From Cambridge University .

Olny srmat poelpe can raed tihs.
I cdnuolt blveiee taht I cluod aulaclty uesdnatnrd waht I was rdanieg. The phaonmneal pweor of the hmuan mnid, aoccdrnig to a rscheearch at Cmabrigde Uinervtisy, it deosn't mttaer in waht oredr the ltteers in a wrod are, t he olny iprmoatnt tihng is taht the frist and lsat ltteer be in the rghit pclae. The rset can be a taotl mses and you can sitll raed it wouthit a porbelm. Tihs is bcuseae the huamn mnid deos not raed ervey lteter by istlef, but the wrod as a wlohe. Amzanig huh? yaeh and I awlyas tghuhot slpeling was ipmorantt!"

(What is scary is that my spell check only catches 3 words out of that mess.)

Re: get_words_from_a_number_which_is_passed_as_a_perimeter_into_this_function

2012-04-17 13:33 • by Nagesh
That mail in circulate since birth of internet. Tim Berner Lee write it!

Re: get_words_from_a_number_which_is_passed_as_a_perimeter_into_this_function

2012-04-17 13:43 • by Tim Berner Lee (unregistered)
379339 in reply to 379338
Nagesh is right, I did.

Captcha: nimis. My nimis Tim Berner Lee, I help Dan Quail invent the Internet, please to meet you.

Re: get_words_from_a_number_which_is_passed_as_a_perimeter_into_this_function

2012-04-17 13:47 • by Real Tim Berner Lee (unregistered)
379340 in reply to 379339
FAKER Tim Berner Lee:
Nagesh is right, I did.

Captcha: nimis. My nimis Tim Berner Lee, I help Dan Quail invent the Internet, please to meet you.

Faker!!

Re: get_words_from_a_number_which_is_passed_as_a_perimeter_into_this_function

2012-04-17 13:47 • by Strolskon
379341 in reply to 379337
Ben Jammin:

Olny srmat poelpe can raed tihs.

OMG THIS IS SO TRUE I OLWAYS NEW I WAS SMARTER THEN MY FRIENDS (lol i can read it i bet noone else can)).

Ben Jammin:
The phaonmneal pweor of the hmuan mnid

How is identifying a rearranged set of letters "phaonmneal pweor"? I bet Babbage's analytical engine would have managed to do that.


Sorry for the rant. Oh wait, this is TheDailyWTF, I don't have to apologize.

Re: get_words_from_a_number_which_is_passed_as_a_perimeter_into_this_function

2012-04-17 13:55 • by Jeff (unregistered)
379343 in reply to 379341
Strolskon:
Ben Jammin:

Olny srmat poelpe can raed tihs.

OMG THIS IS SO TRUE I OLWAYS NEW I WAS SMARTER THEN MY FRIENDS (lol i can read it i bet noone else can)).
I can read it, but only because I've read it before, so I already know what it says.

Re: get_words_from_a_number_which_is_passed_as_a_perimeter_into_this_function

2012-04-17 14:00 • by Nagesh (unregistered)
379344 in reply to 379336
Nagesh:
Nagesh:
Nagesh:
geoffrey is plain pagal - (crazy).

java has created more value for business. java is not restricted to just business apps, but also used inside your car, your camera, your phone, your alarm clock and everywhere you can care to think of.

So geoffrey is failing in providing any true picture of world.

Here in Hyderabad, we use chicken for alarum clock.


You must stay in slum outside Charminar. I am in Banjara Hills, madarchod!

All India is slum, excepting Goa. Do not believing what you see on TV.

Re: get_words_from_a_number_which_is_passed_as_a_perimeter_into_this_function

2012-04-17 14:15 • by Nagesh
379345 in reply to 379340
Real Tim Berner Lee:
FAKER Tim Berner Lee:
Nagesh is right, I did.

Captcha: nimis. My nimis Tim Berner Lee, I help Dan Quail invent the Internet, please to meet you.

Faker!!


You are equal fake.

Real Tim Berner Lee is not having time to post here, madarchod!

Re: get_words_from_a_number_which_is_passed_as_a_perimeter_into_this_function

2012-04-17 14:18 • by Tud (unregistered)
379346 in reply to 379344
Fake Nagesh:
Nagesh:
Fake Nagesh:
Nagesh:
geoffrey is plain pagal - (crazy).

java has created more value for business. java is not restricted to just business apps, but also used inside your car, your camera, your phone, your alarm clock and everywhere you can care to think of.

So geoffrey is failing in providing any true picture of world.

Here in Hyderabad, we use chicken for alarum clock.


You must stay in slum outside Charminar. I am in Banjara Hills, madarchod!

All India is slum, excepting Goa. Do not believing what you see on TV.


Don't insult India Faker! And learn speaking English better! Do not is shorter and more compatible to say Don't.

Re: get_words_from_a_number_which_is_passed_as_a_perimeter_into_this_function

2012-04-17 14:19 • by Tud (unregistered)
Now that was a real fail.

Re: get_words_from_a_number_which_is_passed_as_a_perimeter_into_this_function

2012-04-17 14:19 • by Remy Martin (unregistered)
I'm sorry to announce that I have some bad news. You've probably already guessed since there was no article today, but Alex unexpectedly passed. This is especially hard on his widow, who is now forced to due both their taxes on her own to avoid an IRS penalty. Please keep her in your prayers.

Re: get_words_from_a_number_which_is_passed_as_a_perimeter_into_this_function

2012-04-17 14:51 • by Zunetang (unregistered)
379350 in reply to 379348
Remy Martin:
I'm pleased to announce that I have some wonderful news. You've probably already guessed since there wasn't another tired, shitty article today, but Alex finally dropped dead. This is especially great news for his windows, which will no longer have to reflect his ugly face. Even the IRS doesn't missing out on his income taxes - the world is such a better place now. Please keep praying for him to wind up in hell. I, for one, am hoping he will suck Satan's cock for all eternity.
Ding! Dong! - The faggot's dead!
(Which old fag?)
The Grecian fag!
Ding, dong, the Grecian faggot's dead!

Lot's 'a love, fuck face!!!

Re: get_words_from_a_number_which_is_passed_as_a_perimeter_into_this_function

2012-04-17 15:19 • by the (unregistered)
379351 in reply to 379348
Remy Martin:
I'm sorry to announce that I have some bad news. You've probably already guessed since there was no article today, but Alex unexpectedly passed. This is especially hard on his widow, who is now forced to due both their taxes on her own to avoid an IRS penalty. Please keep her in your prayers.


You must be new here. Alex frequently posts a lame wtf and then skips a day just to piss people off.

Re: get_words_from_a_number_which_is_passed_as_a_perimeter_into_this_function

2012-04-17 15:34 • by AGray (unregistered)
379352 in reply to 379187
Best rewritten:


If String.IsNullOrEmpty(p_mode) Then
p_mode = "No parameter was passed through."
End If


The value of KISS is not lost on me. The engineering principle is pretty good, too.

Re: get_words_from_a_number_which_is_passed_as_a_perimeter_into_this_function

2012-04-17 15:34 • by AGray (unregistered)
379353 in reply to 379187
Best rewritten:


If String.IsNullOrEmpty(p_mode) Then
p_mode = "No parameter was passed through."
End If


The value of KISS is not lost on me. The engineering principle is pretty good, too.

Re: get_words_from_a_number_which_is_passed_as_a_perimeter_into_this_function

2012-04-17 15:37 • by AGray (unregistered)
379354 in reply to 379352
Better still:

If String.IsNullOrEmpty(p_mode) Then
Throw New ArgumentNullException("p_mode")
End If

Re: get_words_from_a_number_which_is_passed_as_a_perimeter_into_this_function

2012-04-17 15:37 • by Ben Jammin (unregistered)
379355 in reply to 379351
the:
Remy Martin:
I'm sorry to announce that I have some bad news. You've probably already guessed since there was no article today, but Alex unexpectedly passed. This is especially hard on his widow, who is now forced to due both their taxes on her own to avoid an IRS penalty. Please keep her in your prayers.


You must be new here. Alex frequently posts a lame wtf and then skips a day just to piss people off.


You must be new here. When Alex skips a day to piss people off, Remy notifies us that Alex has passed.

P.S. When my Captcha is filled out by my browser's auto form filler... it is probably ineffective.

Re: get_words_from_a_number_which_is_passed_as_a_perimeter_into_this_function

2012-04-17 15:44 • by Saxton! (unregistered)
379356 in reply to 379350
Zunetang:
Remy Martin:
I'm pleased to announce that I have some wonderful news. You've probably already guessed since there wasn't another tired, shitty article today, but Alex finally dropped dead. This is especially great news for his windows, which will no longer have to reflect his ugly face. Even the IRS doesn't missing out on his income taxes - the world is such a better place now. Please keep praying for him to wind up in hell. I, for one, am hoping he will suck Satan's cock for all eternity.
Ding! Dong! - The faggot's dead!
(Which old fag?)
The Grecian fag!
Ding, dong, the Grecian faggot's dead!

Lot's 'a love, fuck face!!!


Dude, relax.

Re: get_words_from_a_number_which_is_passed_as_a_perimeter_into_this_function

2012-04-17 15:57 • by the beholder (unregistered)
379357 in reply to 379348
Remy Martin:
I'm sorry to announce that I have some bad news. You've probably already guessed since there was no article today, but Alex unexpectedly passed. This is especially hard on his widow, who is now forced to due both their taxes on her own to avoid an IRS penalty. Please keep her in your prayers.
Oh we're not worried. You already said he died a few days ago, and then in the next day he got better.

Re: get_words_from_a_number_which_is_passed_as_a_perimeter_into_this_function

2012-04-17 16:05 • by Impatient Captcha wizard (unregistered)
379358 in reply to 379355
Ben Jammin:
the:
Remy Martin:
I'm sorry to announce that I have some bad news. You've probably already guessed since there was no article today, but Alex unexpectedly passed. This is especially hard on his widow, who is now forced to due both their taxes on her own to avoid an IRS penalty. Please keep her in your prayers.


You must be new here. Alex frequently posts a lame wtf and then skips a day just to piss people off.


You must be new here. When Alex skips a day to piss people off, Remy notifies us that Alex has passed.

P.S. When my Captcha is filled out by my browser's auto form filler... it is probably ineffective.

Doesn't matter. The captcha is just a minor deterrence. What actually prevents users from posting is Akismet.

acsi
aliquam
amet
aptent
bene
consequat
cogo
eros
facilisis
genitus
gravis
haero
nimis
mara
oppeto
opto
paratus
pecus
populus
plaga
praesent
quis
saepius
saluto
tation
tristique
valetudo
validus
vereor
verto
vindico

PS: I like the fact that when you hit "Preview" it generates a different one with the same word.

Re: get_words_from_a_number_which_is_passed_as_a_perimeter_into_this_function

2012-04-17 16:31 • by Real Advertiser (unregistered)
If I was paying a newspaper to run my ads and they decided to put out an issue whenever they darn well felt like it, I'd immediately pull my ads and sue them for damages.

Re: get_words_from_a_number_which_is_passed_as_a_perimeter_into_this_function

2012-04-17 16:45 • by DirkAndTheMac (unregistered)
379360 in reply to 379177
The bugs fixed were hysterical, the icing on a very splendid cake.... Somehow managed to misspell 'three' in the first iteration and whilst fixing that failed to notice that 5 would be 'four'..... Later on he even admits to having to shorten the name of the function from it's now concise name!!

Re: get_words_from_a_number_which_is_passed_as_a_perimeter_into_this_function

2012-04-17 19:18 • by Silverhill
379361 in reply to 379359
Real Advertiser:
If I was paying a newspaper to run my ads and they decided to put out an issue whenever they darn well felt like it, I'd immediately pull my ads and sue them for damages.
BFD. You're not paying Alex anything for his freely-provided work, and you think you have a right to complain? Grow up, weenie.

Re: get_words_from_a_number_which_is_passed_as_a_perimeter_into_this_function

2012-04-17 22:02 • by Friedrice The great (unregistered)
379362 in reply to 379287
RS:
Hey Nagesh is not the only one guilty of butchering the English language. I work with many WASPs and their use of the English language is not much better.


Weird Anti-Social Perverts?

Re: get_words_from_a_number_which_is_passed_as_a_perimeter_into_this_function

2012-04-17 22:22 • by frits
379363 in reply to 379362
Friedrice The great:
RS:
Hey Nagesh is not the only one guilty of butchering the English language. I work with many WASPs and their use of the English language is not much better.


Weird Anti-Social Perverts?
I thought he was referring to a bunch of Blackie Lawlesses.

Re: get_words_from_a_number_which_is_passed_as_a_perimeter_into_this_function

2012-04-17 22:52 • by da Doctah
379364 in reply to 379335
Nagesh:
Nagesh fake:
Not understand. Wasp is insect meking nest in corner of my ofice. We are not being able to kil this leving creatures, even though I am geting stinged daily. :(


WASP do not bite, faker!


Sting != bite, fakir!

Re: get_words_from_a_number_which_is_passed_as_a_perimeter_into_this_function

2012-04-17 22:59 • by omfg (unregistered)
379365 in reply to 379173
>13-19 becomes easy (nine) + (teen)

threeteen
fiveteen
eightteen

still better than "five" randomly printed for 4, though

Misspelled 3

2012-04-18 01:46 • by North Shore Beach Bum (unregistered)
In Hawai`i, we pronounce "3" the same as tree and rarely use plurals.

Numbah tree day of Christmas, my tutu gave to me:
tree dry squid,
two coconut,
and one myna bird in one papaya tree!

Re: get_words_from_a_number_which_is_passed_as_a_perimeter_into_this_function

2012-04-18 04:52 • by oheso
379369 in reply to 379222
Cad Delworth:
For example, try asking for a "fanny pack" in a shop in England and see what you get (possibly including being thrown out of the shop!).


Depending, of course, on the sort of shop!

Re: get_words_from_a_number_which_is_passed_as_a_perimeter_into_this_function

2012-04-18 04:57 • by oheso
379370 in reply to 379248
¯\(°_o)/¯ I DUNNO LOL:
Yeah, I remember ol' HX_373. He was THX_1138's granddad, ya know. And when he got to drinking, he would get as pissed as a parameter!


<3

Re: get_words_from_a_number_which_is_passed_as_a_perimeter_into_this_function

2012-04-18 06:12 • by null (unregistered)
379372 in reply to 379348
Remy Martin:
I'm sorry to announce that I have some bad news. You've probably already guessed since there was no article today, but Alex unexpectedly passed.


Was a he passed as a perimeter?
if (todaysWtf == null)
return "No Alex was passed.";

Captcha 'incassum' -- they should keep a couple of spare Wtf's laying around incassum Alex doesn't feel like posting on a given day.

Re: get_words_from_a_number_which_is_passed_as_a_perimeter_into_this_function

2012-04-18 08:06 • by Real Advertiser (unregistered)
379374 in reply to 379361
Silverhill:
Real Advertiser:
If I was paying a newspaper to run my ads and they decided to put out an issue whenever they darn well felt like it, I'd immediately pull my ads and sue them for damages.
BFD. You're not paying Alex anything for his freely-provided work, and you think you have a right to complain? Grow up, weenie.


Oh...you must have the ads on the side blocked then.

How does your foot taste?

Re: get_words_from_a_number_which_is_passed_as_a_perimeter_into_this_function

2012-04-18 10:30 • by TheSHEEEP (unregistered)
Are you people nuts?

"Tokyo & Beijing - see you at QCon (April 16-20) "

I'm pretty sure this has SOMETHING to do with the absence of new articles...

Re: get_words_from_a_number_which_is_passed_as_a_perimeter_into_this_function

2012-04-18 10:36 • by erat (unregistered)
379378 in reply to 379240
Tasty:
KattMan:
Honestly it's a language parser, should be easy to do all numbers with little more code.

Go 1-9, then 10-12, then 13-19 becomes easy (nine) + (teen)
After that everything else is easy 21, 31 are (twenty) + (one) or (thirty) + (one).

Yeah this function is a serious WTF, even in its name, sounds like the forgot to name it and just put the comment as the name.


Never depend on logic when using natural languages!

Your 13-19 range doesn't quite work. For example:

three+teen != "thirteen"
five+teen != "fifteen"

Bonus Spanish language oddity:
The "hundreds" in Spanish have an irregular 500.

cien (100)
dos cientos (200)
tres cientos (300)
...
quinentos (500) (the first N is N+~)


Just for your information: 700 (setecientos / siete cientos) and 900 (novecientos / nueve cientos) are also irregular... just saying.

Re: get_words_from_a_number_which_is_passed_as_a_perimeter_into_this_function

2012-04-18 10:37 • by daveime
There's so many WTFs I don't know where to start.


'***************************** Example Usage**********************************************

' WORD_CONVERTED_FROM_A_NUMBER_PASSED_THROUGH_A_PERIMETER("pass_a_number","13,387,281")
'
' would return: thirteen million three hundred and eighty seven thousand two hundred and eighty one


Except it only works for numbers up to 15, including "eleevn" and "forteen".

I think I discovered why it's version 15.1 ... that's the range of numbers it actually works for !

Future plans ... after the first 1000 it's going to get easier, so we can start using exponential upgrades ! Although memory is going to get a bit tight by 100 million, as it will take around 7GB just to store the code.

Re: get_words_from_a_number_which_is_passed_as_a_perimeter_into_this_function

2012-04-18 11:35 • by depressed cheescake (unregistered)
379381 in reply to 379374
Real Advertiser:
Silverhill:
Real Advertiser:
If I was paying a newspaper to run my ads and they decided to put out an issue whenever they darn well felt like it, I'd immediately pull my ads and sue them for damages.
BFD. You're not paying Alex anything for his freely-provided work, and you think you have a right to complain? Grow up, weenie.


Oh...you must have the ads on the side blocked then.

How does your foot taste?


Presumably you mean the Buildmaster ads from Inedo, you know the company Alex works for? Guess they're probably not too bothered.

More to the point why do *you* give a shit about whether advertising revenue is well spent on this site?

Re: get_words_from_a_number_which_is_passed_as_a_perimeter_into_this_function

2012-04-18 11:51 • by bad_management (unregistered)
Perimeter, parameter.
Toe-may-toe, toe-mah-toe.
Poe-tay-toe, poe-tah-toe.

Re: get_words_from_a_number_which_is_passed_as_a_perimeter_into_this_function

2012-04-18 12:52 • by Orwellian_Startrek (unregistered)
379386 in reply to 379327
[quote user="wonk"][quote=Article] 'Sometimes a 'four' would be outputted when '5' was passed through the perimeter[/quote]
NOW that episode of Star Trek makes sense. Heh. 4 lights....[/quote]

Lights? Star Trek?

You realize that that episode was a ripoff from 1984, right? (4 fingers)

Re: get_words_from_a_number_which_is_passed_as_a_perimeter_into_this_function

2012-04-18 12:58 • by Jay (unregistered)
379388 in reply to 379252
no:
Bleat:
'API call removed due to high demand

1) How much was this used that this was ever in 'high demand'


Well, it never was defined what kind of 'high demand' - as in 'all his colleagues demanded that his hands be separated from his arms before being allowed near a computer again'


Or, The only time people demand this function is when they are high on something.

Re: get_words_from_a_number_which_is_passed_as_a_perimeter_into_this_function

2012-04-18 13:07 • by Jay (unregistered)
379395 in reply to 379296
ozzie:
mschaad:
I just appreciated the fact that the English output is still wrong.

[GrammarNazi]
13,387,281 rendered as words should read
"thirteen million three hundred eighty-seven thousand two hundred eighty-one". Note that the word "and" is not in there at all, and tens are properly hyphenated. :-)
[/GrammarNazi]

Also, to render numbers correctly as words (with the hyphens and everything) is a harder trick than you might think.
Thankfully, standard English style dictates that you pretty much never spell out any numbers above nine.

So where would you need a library like this, unless your app writes checks?


[SpellingNazi]
You mean cheques?
[/SpellingNazi]

Captcha - opto - I opto point out your spelling mistakes while you point out grammar mistakes.


Umm, maybe because he has an app that prints checks?

RE SpellingNazi: No, that should be UKEnglishNazi. In real modern English, you know, US English, we spell it "checks".

Re: get_words_from_a_number_which_is_passed_as_a_perimeter_into_this_function

2012-04-18 13:11 • by Jay (unregistered)
379399 in reply to 379337
Ben Jammin:
frits:
A 'Brit':
The British tic of critiquing American English is one of the many reasons I loathe British people on the internet.


The American tic of loathing the English defending their language (notice that the Scots, Welsh and Irish won't defend it); and getting confused between Britain and the coutries that make it, is one of the many reasons I loathe Armerican people on the internet.

The opinions of folks from a fallen empire which has shrunken to the size of the Philadelphia metro area do not interest me.


Language is meant to communicate ideas. If those on the receiving end can interpret the original idea, then success.

"From Cambridge University .

Olny srmat poelpe can raed tihs.
I cdnuolt blveiee taht I cluod aulaclty uesdnatnrd waht I was rdanieg. The phaonmneal pweor of the hmuan mnid, aoccdrnig to a rscheearch at Cmabrigde Uinervtisy, it deosn't mttaer in waht oredr the ltteers in a wrod are, t he olny iprmoatnt tihng is taht the frist and lsat ltteer be in the rghit pclae. The rset can be a taotl mses and you can sitll raed it wouthit a porbelm. Tihs is bcuseae the huamn mnid deos not raed ervey lteter by istlef, but the wrod as a wlohe. Amzanig huh? yaeh and I awlyas tghuhot slpeling was ipmorantt!"

(What is scary is that my spell check only catches 3 words out of that mess.)


We do, however, give bonus points for making text easy to understand. If I write, "I went to the store", you can very quickly discern my meaning. If I write, "i wnet ot het tsoer", you may be able to figure it out, but it takes considerably longer. Likewise if I write, "I perambulated to the retail establishment", or any of other numerous senseless added obfuscations, you have to think for an extra second or two. My time is too valuable to waste on people who cannot express their thoughts clearly.

Re: get_words_from_a_number_which_is_passed_as_a_perimeter_into_this_function

2012-04-18 15:30 • by HotelBravoMike (unregistered)
379439 in reply to 379302
Well, I took a shot at it:

+ my version can do German and English
+ the range is bigger than just 0 to 15
+ I spell 'eleven' (or 'Elf') correctly

- use of global variables not really ideal
- limited range (-2*10e9 to +2*10e9)

I actually thought this was necessary due to a 32bit machine - however with TCL (everything is a string) this is not really a restriction. As long as I do not calculate with the so called integers. ;)

I am not sure if the created german words are to be concatenated or separate. (Embarrasingly for native speake, I know.)

For Example:
the number 1,403,211
Eine Million Vierhundertdrei Tausend Zweihundertelf
... does not look right to me
Einemillionvierhundertdreitausendzweihundertelf
... is not really very readable

I decide to present the version which is more readable.

If someone could give an educated opinion on that please.....

So, code works in 2 parts:

a) setup

setup de
or
setup en

... declares 2 global varables called 'language' and 'numbers'

b) conversion

set text_representation [int2txt decimal_representation]
e.g.
puts [int2txt 123456789]
-->
onehundredtwentythree million, fourhundredfiftysix thousand, sevenhundredeightynine
or
Einhundertdreiundzwanzig Millionen Vierhundertsechsundfünfzig Tausend Siebenhundertneunundachtzig



## #
## # setup a language
## #

proc setup {la} {
global language numbers
set language $la
# remove existing configuration to prevent contamination
if {[info exists numbers]} {unset numbers}
# select from list of supported languages
switch -exact -- $la {
en {
set numbers(0) zero
set numbers(1to9) [list one two three four five six seven eight nine]
set numbers(10to19) [list ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen]
set numbers(20to90) [list twenty thirty fourty fifty sixty seventy eighty ninety]
set numbers(100) hundred
set numbers(pow3) [list thousand million billion]
set numbers(neg) minus
set numbers(ovr) "over two billion"
set numbers(undr) "less than minus two billion"
# 3 digit partitioning, example: one million <AND> twohundred thousand <AND> twelve
#set numbers(and) "and "
set numbers(and) "\b, "
#set numbers(and) ""
}
de {
set numbers(0) Null
set numbers(1) Eins
set numbers(1to19) [list ein zwei drei vier fünf sechs sieben acht neun zehn \
elf zwölf dreizehn vierzehn fünfzehn sechzehn siebzehn achtzehn neunzehn]
set numbers(20to90) [list zwanzig dreisig vierzig fünfzig sechzig siebzig achtzig neunzig]
set numbers(100) hundert
set numbers(pow3.0) [list tausend million milliarde]
set numbers(pow3.1) [list tausend millionen milliarden]
set numbers(pow3.ending) [list s {} e e]
set numbers(neg) Minus
set numbers(ovr) "Über Zwei Milliarden"
set numbers(undr) "Weniger als Minus Zwei Milliarden"
}
default {
puts stderr "'$la' is not a supported language - please choose 'en' or 'de' - exiting."
exit 1
}
}
set numbers(upper) [expr (1 << 31) - 1]
set numbers(lower) [expr (1 << 31)]
}

## #
## # translate integer to text
## #

# Note: in TCL everything is a string, so no explicit format %d conversion

# integer into segments of 3 digits, empty string if segment is '000'
proc to3digits {i} {
set l [list ]
set le [string length $i]
# split into set of 3 digits each
set n -1
for {set p1 [expr $le-3]; set p2 [expr $le-1]} {$p2 >= 0} {incr p1 -3; incr p2 -3} {
set s [string range $i $p1 $p2]
regsub {^0+} $s "" s
incr n; set di($n) $s
}
# reverse list
for {} {$n >= 0} {incr n -1} {
lappend l $di($n)
}
return $l
}

# german locale (de)
proc 3digits2txt.de {d} {
global numbers
set s ""
if {$d >= 100} {
set hundreds [expr ($d/100)]
set s [lindex $numbers(1to19) [expr $hundreds-1]]
append s $numbers(100)
set d [expr $d % 100]
}
if {$d == 0} {return $s}
if {$d < 20} {
append s [lindex $numbers(1to19) [expr ($d%20)-1]]
} else {
set tens [expr $d/10]
set ones [expr $d%10]
if {$ones > 0} {
append s [lindex $numbers(1to19) [expr $ones-1]]
append s und
}
append s [lindex $numbers(20to90) [expr $tens-2]]
}
return $s
}
proc int2txt.de {i} {
global language numbers
if {$i == 1} {return $numbers(1); return}
set di [to3digits $i]
set pow [llength $di]
incr pow -1
set txt ""
foreach d $di {
incr pow -1
if {$d == {}} {continue}
set s [3digits2txt.de $d]
set plural 1
if {[expr $d%100] == 1} {
set plural 0
append s [lindex $numbers(pow3.ending) [expr $pow+1]]
}
if {$pow >= 0} {
append txt [format "%s %s " [string totitle $s] [string totitle [lindex $numbers(pow3.$plural) $pow]]]
} else {
append txt [format "%s " [string totitle $s]]
}
}
return $txt
}
# english locale (en)
proc 3digits2txt.en {d} {
global numbers
set s ""
if {$d >= 100} {
set hundreds [expr ($d/100)]
set s [lindex $numbers(1to9) [expr $hundreds-1]]
append s $numbers(100)
set d [expr $d % 100]
}
if {$d == 0} {return $s}
if {$d < 20} {
if {$d < 10} {
append s [lindex $numbers(1to9) [expr ($d%10)-1]]
} else {
append s [lindex $numbers(10to19) [expr ($d%20)-10]]
}
} else {
append s [lindex $numbers(20to90) [expr ($d/10)-2]]
append s [lindex $numbers(1to9) [expr ($d%10)-1]]
}
return $s
}

proc int2txt.en {i} {
global numbers
set di [to3digits $i]
set pow [llength $di]
incr pow -1
set and ""
set txt ""
foreach d $di {
incr pow -1
if {$d == {}} {continue}
set s [3digits2txt.en $d]
if {$pow >= 0} {
append txt [format "%s%s %s " $and $s [lindex $numbers(pow3) $pow]]
} else {
append txt [format "%s%s " $and $s]
}
set and $numbers(and)
}
return $txt
}

# main converter (calls locale)

proc int2txt {i} {
global language numbers
if {$i == 0} {puts -nonewline $numbers(0); return}
if {$i < $numbers(lower)} {puts -nonewline $numbers(undr); return}
if {$i > $numbers(upper)} {puts -nonewline $numbers(ovr); return}
if {$i < 0} {
set i [expr abs($i)]
puts -nonewline [format "%s " $numbers(neg)]
}
int2txt.$language $i
}



Looks OK in preview so lets submit. ;)

Re: get_words_from_a_number_which_is_passed_as_a_perimeter_into_this_function

2012-04-18 15:54 • by HotelBravoMike (unregistered)
379444 in reply to 379439
Arghhh.. what a right mess-up on the main converter call.
(The initial version printed directly to console instead of returning the string.)

This should do the trick


# main converter (calls locale)

proc int2txt {i} {
global language numbers
if {$i == 0} {return $numbers(0)}
if {$i < $numbers(lower)} {return $numbers(undr)}
if {$i > $numbers(upper)} {return $numbers(ovr)}
if {$i < 0} {
set i [expr abs($i)]
return [format "%s %s" $numbers(neg) [int2txt.$language $i]]
}
return [int2txt.$language $i]
}

Re: get_words_from_a_number_which_is_passed_as_a_perimeter_into_this_function

2012-04-18 16:17 • by Dutchie (unregistered)
Over at stackoverflow.com there are some nice solutions like this one.

Re: get_words_from_a_number_which_is_passed_as_a_perimeter_into_this_function

2012-04-18 16:38 • by Nemo (unregistered)
379448 in reply to 379299
I found my earlier version had some float/int problems with larger numbers, and I was taking the wrong field for the overall limit. So, version 2:

http://pastebin.com/xq66a3H3

Re: get_words_from_a_number_which_is_passed_as_a_perimeter_into_this_function

2012-04-18 17:07 • by NRC (unregistered)
379455 in reply to 379178
Looks like a novice programmer struggling with immutable strings. I wonder how many hours were spent trying to figure out why p_mode.Replace() did not actually replace the characters in that instance, before giving up (but still leaving the pointless code in there).

Re: get_words_from_a_number_which_is_passed_as_a_perimeter_into_this_function

2012-04-18 17:28 • by zzo38
379459 in reply to 379295
Silverhill:

zzo38:
<snip>
5:twelve-th]:twelvth
This was written on the Twelfth of Never, right?
Oops! Thanks for notifying me this mistake, I will fix it

Re: get_words_from_a_number_which_is_passed_as_a_perimeter_into_this_function

2012-04-18 17:53 • by Acacio (unregistered)
Wow, just wow. I've read a lot of stupid stuff in the DWTF but this one is just ... wow.
In so many dimensions....

We can close DWTF: after this one, all the rest will paleas watered down beer.
« PrevPage 1 | Page 2 | Page 3 | Page 4 | Page 5Next »

Add Comment