For an input number say 232, I wanted to be able to write out the number in text form: two hundred thirty two. I have an array which holds these numbers
Array[0] = 2, Array[1] = 3, Array[2] = 2.
I have written a
switch statement
which sees the number and prints it text, example two hundred three two. I don’t know how transform that “three” into “thirty” dynamically. Suppose I have more numbers to spell, like 452,232.
You can’t handle digits independently, it’s that simple.
For example, the text for
21is the concatenation of “twenty” and “one”, but the text for11is not the concatenation of “ten” and “one”.Also, “1001” doesn’t become “one thousand zero hundred zero one”.
You can use function calls to keep logic complexity down, but you’re going to need logic to look at multiple digits at once.