convert integer number to string text
-
Hi all please how i can convert integer number to string text like this (i entered 7 in keyboard and the output will be seven) thank's for all
-*-*-*-*-*-*-*-*-* To Be Or Not To Be (KARFER) -*-*-*-*-*-*-*-*-*
you may use the function
sprintf
function, for instanceint i;
char buffer[20];/* just make sure the buffer is big enough */
i=7;
sprintf(buffer,"%d", i);or, if you prefer the
CString
classint i;
CString str;
i=7;
str.Format("%d", i);:)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
[my articles] -
Hi all please how i can convert integer number to string text like this (i entered 7 in keyboard and the output will be seven) thank's for all
-*-*-*-*-*-*-*-*-* To Be Or Not To Be (KARFER) -*-*-*-*-*-*-*-*-*
CP holds some articles on number-to-text conversion. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Happy 2008!
-
Hi all please how i can convert integer number to string text like this (i entered 7 in keyboard and the output will be seven) thank's for all
-*-*-*-*-*-*-*-*-* To Be Or Not To Be (KARFER) -*-*-*-*-*-*-*-*-*
And see The Complete Guide to C++ Strings, Part II - String Wrapper Classes[^] for other converts.
-
Hi all please how i can convert integer number to string text like this (i entered 7 in keyboard and the output will be seven) thank's for all
-*-*-*-*-*-*-*-*-* To Be Or Not To Be (KARFER) -*-*-*-*-*-*-*-*-*
If I understood you well, you are asking how to get the name of the number, not the number itself inside a string. So you are not asking for:
int iNumberSeven = 7; CString csAux = ""; csAux.Format("%i",iNumberSeven);
you are asking for something like:if (iNumberSeven == 7) { csAux = "seven"; }
If you meant the second option, the only way I can think of is to try to generate the numbers programmatically. And this would mean to study the way the numbers are formed and of course having some basic strings in a vault in order to be able to use them. -
you may use the function
sprintf
function, for instanceint i;
char buffer[20];/* just make sure the buffer is big enough */
i=7;
sprintf(buffer,"%d", i);or, if you prefer the
CString
classint i;
CString str;
i=7;
str.Format("%d", i);:)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
[my articles] -
Hi all please how i can convert integer number to string text like this (i entered 7 in keyboard and the output will be seven) thank's for all
-*-*-*-*-*-*-*-*-* To Be Or Not To Be (KARFER) -*-*-*-*-*-*-*-*-*