Numbers to Words
There are varying opinions amongst writers as to when one should spell out a number vs. using figures. However there are a few generally agreed upon rules for doing so.
There are 2 of them we will follow for this kata:
- Numbers beginning a sentence should be spelt out.
- Hyphenate all compound numbers from twenty-one through ninety-nine
Assume all the numbers given start sentences and your code will be used like a spell checker for grammar issues related to numbers.
Only worry about up numbers up to 4 digits long. Assume all numbers are positive.
|1 digit||2 digits||3 digits||4 digits|
|0 = zero||10 = ten||100 = one hundred||2000 = two thousand|
|5 = five||21 = twenty-one||303 = three hundred three||3466 = three thousand four hundred sixty-six|
|8 = eight||77 = seventy-seven||555 = five hundred fifty-five||2400 = two thousand four hundred|
Solve for 1 digit, then move to 2 digits and so on.
The simplest way to express large numbers is usually best. Instead of 5300 being equal to five thousand three hundred it should return fifty-three hundred. This new rule only applies to 4 digit numbers.