0

Say I got a number, I enter it in. (like 5). Now I want to convert that to a text string that represents that number (five).

I also want it so that if I were to print a big number like 543 or something it will print that out in its text format.

8
Contributors
10
Replies
11
Views
8 Years
Discussion Span
Last Post by ArkM
Featured Replies
  • 1
    Aia 1,977   8 Years Ago

    What a way of missing the boat! None of your suggestions are a solution. The OP wants to have it display as a text. [B][I]e.i.[/I][/B] 5 = Five, 6 = Six tux4life> [...] then you should try itoa I hope you understand that itoa is not a standard C function. Read More

1

What a way of missing the boat!
None of your suggestions are a solution.
The OP wants to have it display as a text.
e.i. 5 = Five, 6 = Six

tux4life> [...] then you should try itoa
I hope you understand that itoa is not a standard C function.

0

tux4life> [...] then you should try itoa
I hope you understand that itoa is not a standard C function.

Yes I know, thus actually this was a bad suggestion :(

What a way of missing the boat!
None of your suggestions are a solution.
The OP wants to have it display as a text.
e.i. 5 = Five, 6 = Six

You're totally right, I didn't read his question carefully enough :(

The simplest solution I know is by putting all the text representations of a number into an array, like this:

char *num[] = {
"",
"one",
"two",
"three",
"four",
"five",
"six",
"seven",
"eight",
"nine",
"ten"
/* And so on ... */
};

Now if you want to convert the number 5 for example to "five" and display it on the screen, you just add the following line to your code: printf("%s\n", num[5]);

0

Also if your looking for large numbers lets say 5400 and you want to write five thousand you could count the digits. So the number 5 is the forth number from the end which makes it easy to determine it represents 5 thousand. The number 4 is three digits in so it represents hundres etc..

0

Also if your looking for large numbers lets say 5400 and you want to write five thousand you could count the digits. So the number 5 is the forth number from the end which makes it easy to determine it represents 5 thousand. The number 4 is three digits in so it represents hundres etc..

Yes, but apply the same rule to 15000, 1500, 150 and 15, what now?

0

>Yes, but apply the same rule to 15000, 1500, 150 and 15, what now?
It works fine? As long as you have the right special cases for identifying a teen and ignoring zeros, all is well with _Nestor's logic.

0

>Yes, but apply the same rule to 15000, 1500, 150 and 15, what now?
It works fine? As long as you have the right special cases for identifying a teen and ignoring zeros, all is well with _Nestor's logic.

Oh, as I'm not a native speaker I forgot about the English language rules for forming a number, if you write a program which can successfully apply these rules, it's all OK :)

And of course such a converter is better than just storing all text-representations in every way, for example it doesn't take up a lot of memory (this is rather for big numbers), you won't have to put all your effort in manually inputting all the text-representations of each number :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.