sprintf more useful
Float 2 Char
You can use sprintf (): For example, float,double to char#include<stdio.h> #include <stdlib.h> void Main () {float f= 1234.5; Double d= 789.8765;char sf[20],sd[20];sprintf (SF, "%f", f); float to charsprintf (SD, "%LF", D); Double to char printf ("%s%s\n", SF,SD); To come out to see}
Char 2 float
You can use the library function atof.
1 Function name Atof
2 statement
Double atof (const char *nptr);
3 Header Files
#include <stdlib.h>
4 Features
Converts the string in the parameter nptr to floating-point data and returns.
5 It is important to note that a valid string, that is, a string stored in real or scientific notation, can be converted or the conversion will go wrong. For example, a string such as "SJDHK" cannot be converted to a floating-point number. In the case of a "1.23sdf" form, it will only be processed to the last number, and the result is 1.23.
5 Sample Code
String to floating-point integer to floating-point number