Friday, February 5, 2010

Numbers To Words Multi-Language On PHP

It's probably lots of them when u seacrh it. But it has some simplicity on it to add new knowledge about the spelling word of some x digits number.
To build this algorithm, it's important to recognizing the pattern of spelling words for some numbers.

212           =>   two hundred twelve
345867     =>   three hundred forty five thousand eight hundred sixty seven

By those numbers and the translation in words, It could conclude that : 
  • there is some exceptions in the pattern
    ex :    10 => ten            not    onety
             12 => twelve       not    ten two
             20 => twenty       not    twoty
    by this conclution the dictionary (knowledge) to build have to give the knowledgement about those exceptions
  • there id repetition pattern in word "hundred" before and after "thousand". For that reason, it could simplify to devide the algorithm that translate 3 digits numbers from the global algorithm that translate x digits numbers.
My implementation is write down below :