the output shows on the display screen only using printf.
How to convert a floating point number to a string of a certain format?
We can use the sprintf function to save the results to an array of strings.
/*
Example:convert float to string in C language
*/
#include <stdio.h>
#include <stdlib.h>
int main()
{
float f = 1.23456789;
char c[20];
// Rounded to 5 decimal places
sprintf(c, "%.5f", f);
printf(c);
printf("\n");
}
output:
1.23457