Open In App

C Program For Double to String Conversion

Last Updated : 01 Aug, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

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




// C Program to demonstrate
// Double to String Conversion
#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


Next Article

Similar Reads