C - Double to String Conversion Code Example

The code for Double to String Conversion

#include <stdio.h>

int main() {
  // Create a double variable and assign value
  double x = 12345.678901;
  
  // Create a string to store string value
  char result[32];
  
  // Using sprintf() to convert double to string
  sprintf(result, "%f", x);
  
  // Printing the value
  printf("Double valuue (x) : %f\n", x);
  printf("String valuue (result) : %s\n", result);
  
  return 0;
}

/*
Output:
Double valuue (x) : 12345.678901
String valuue (result) : 12345.678901
*/
Code by IncludeHelp, on August 14, 2022 21:15

Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.