C Program For Double to String Conversion
Last Updated :
01 Aug, 2022
To convert double to string in C language, we will use the sprintf function as follows:
Input:
n = 456321.7651234
Output:
string: 456321.7651234
Method: Using sprintf
By specifying the precision in sprintf, we can convert double to string or character array with custom precision. We can use sprintf to add extra text (as required) to the string at the same time.
C
#include <stdio.h>
int main()
{
double n = 456321.7651234;
char str[100];
sprintf (str, "%f" , n);
printf ( "the string is: %s\n" , str);
return 0;
}
|
Output
the string is: 456321.765123
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...