This blog is under construction

Saturday, 6 July 2013

C program to convert float to string

Write a C program to convert float to string.

  #include <stdio.h>
  #include <string.h>

  int main() {
        float input;
        char str[100];
        /* input float value */
        printf("Enter your float value:");
        scanf("%f", &input);

        /* converting float value to string and storing it in str */
        snprintf(str, sizeof(str), "%.4f", input);
        printf("Float Value converted to string: %s\n", str);
        return 0;

  jp@jp-VirtualBox:~/$ ./a.out
  Enter your float value:234.4565
  Float Value converted to string: 234.4565

No comments:

Post a Comment