The char string is converted to a number of integers, and of course only the strings are stored with ' 0 ' ~ ' 9 ' characters, typically using the Atoi function:
#include <stdlib.h>
int atoi (const char *nptr);//The number of integers after conversion
and integral type, there are two ways to convert a floating-point number to a string: one is a function implementation, the other is a format output; The function implementation method is relatively tedious, you can use the itoa () function, but the function cannot be ported, and another way is recommended--format output:
#include <stdio.h>
int sprintf (char *str, const char *format, ...);
int snprintf (char *str, size_t size, const char *format, ...);
The above two methods are relatively simple to implement:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
Char BUF[20];
Double pi = 3.1415926
memset (buf, 0, sizeof (BUF));
sprintf (buf, "%.7LF", pi); Floating-point data defaults to only 6 digits after the decimal point, where the number of digits written is specified
printf ("%s\n", buf);
return 0;
}
This method allows a floating-point data to be converted to a string, while snprintf () is the number of bytes that need to be added to the floating-point data in the BUF.