How can I convert a number to a string?

The standard C library provides several functions for converting numbers of all formats (integers, longs, floats, and so on) to strings and vice versa  The following functions can be used to convert integers to strings: Function Name Purpose itoa() Converts an integer value to a string. ltoa() Converts a long integer value to a string. ultoa() Converts an unsigned long integer value to a string.  The following functions can be used to convert floating-point values to strings: Function Name Purpose ecvt() Converts a double-precision floating-point value to a string without an embedded decimal point. fcvt() Same as ecvt(), but forces the precision to a specified number of digits. gcvt() Converts a double-precision floating-point value to a string with an embedded decimal point.  

Showing Answers 1 - 7 of 7 Answers

supriya ahire

  • Mar 22nd, 2006
 

hi,

   we can convert number to string using built in function itoa().

  Was this answer useful?  Yes

kbjarnason

  • Jul 1st, 2010
 

Note that while itoa, ltoa and the like may be provided, these are not standard functions.  itoa is, but is both unreliable and used for a different purpose.

There is no trivial "one size fits all" answer here, but the simplest example (for signed long ints and lesser beings) would be:

char buff[somesize];
sprintf( buff, "%ld", (long) var );

Modify as needed for larger types, unsigned, etc.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions