How to convert a floating point to ASCII in C?
In C, the best way to convert a floating point into an ASCII string is to use the sprintf() function:
int sprintf( char * buffer, const char *format, ... );
The following example converts a floating point number (pi) to string (str):
#include <stdio.h>
int main()
{
// Floatting point number
float pi = 3.1415;
// String for ASCII value of PI
char str[7];
// Convert and display floatting point to string
sprintf(str, "%.4f", pi);
printf ("pi = %s\n", str);
return 0;
}
In C, the best way to convert a floating point into an ASCII string is to use the sprintf() function:
int sprintf( char * buffer, const char *format, ... );
The following example converts a floating point number (pi) to string (str):
#include <stdio.h>
int main()
{
// Floatting point number
float pi = 3.1415;
// String for ASCII value of PI
char str[7];
// Convert and display floatting point to string
sprintf(str, "%.4f", pi);
printf ("pi = %s\n", str);
return 0;
}
| # | ID | Query | URL | Count |
|---|---|---|---|---|
| 0 | 12024 | en | https://en.ans.wiki/6537/how-to-convert-a-floating-point-to-ascii-in-c | 6 |