Write a C program to convert float to string.
#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;
}
Output:
jp@jp-VirtualBox:~/$ ./a.out
Enter your float value:234.4565
Float Value converted to string: 234.4565
Enter your float value:234.4565
Float Value converted to string: 234.4565
No comments:
Post a Comment