Let's start from scratch.

First, you need to be able to convert values from 0 thru 999 correctly. The hundred's is easy. Then the ten's, then the one's.

Second, if ten's = 1 you have a special case. Add that logic next

Third, add the logic that does the above for every 3 digits to get the thousand, million, billion... you need to count from the right and skip every 3 values until you get to the highest triple, the process as above following it with the magnitude (million, trillion, etc.) The back yo 3 values and do it again.