Pentru al un milionulea de ori…

Jan 06, 2009 17:07


I am converting numbers into words.

OK, so there is code out there to do this already, but the most commonly-cited Ruby solution requires the Linguistics gem, which is HUGE if you just want to display the number of comments on your blog or what-have-you. So I thought I'd have a go at it. It turned out not to be so hard, so I'm kind of internationalising it: so far, I support UK English, US English, French, Esperanto, and Romanian (!). You can check out the test cases (entirely readable by humans, I assure you) to see what it can do.

I have some unanswered questions, if anyone is so inclined:
  • USAnglophones: Can you think of a rule that governs when you use "a hundred" versus "one hundred"? So far, I think I am assuming that, where a speaker of UK English would say "a hundred and twenty-five", you would say "one hundred twenty-five" (again, see the test cases), and only use "a" where the hundred (or the million) is by itself ("a million", not "one million"). But I could be way off-base.
  • In general, I am short on information on pronouncing negative numbers ("minus five") or numbers too big for my calculations (I assume anything over a billion or so is too unwieldy to be required). I can't even do it confidently in French. Ideas? (Again, Americans: "minus five" or "negative five"?)
  • Anyone else like to provide some rules?

It's really interesting seeing how succinctly one can represent a set of rules like this. The champion so far has (predictably) been Esperanto (four rules and fourteen base cases); maybe I'll add Klingon for comparison.

lazyweb, language, code

Previous post Next post
Up