如果你想在浮点数中将字符“a”设置为65.0,那么这样做的方法就是
unsigned char c='a';
float f=(float)(c);//by explicit casting
float fc=c;//compiler implicitly convert char into float.
如果你想在浮动中将字符’9’设置为9.0,那么这样做的方法是
unsigned char c='9';
float f=(float)(c-'0');//by explicit casting
float fc=c-'0';//compiler implicitly convert char into float.
如果你想将包含数字的字符数组转换为浮动,这就是方法
#include
#include
#include
void fun(){
unsigned char* fc="34.45";
//c++ way
std::string fs(fc);
float f=std::stof(fs);//this is much better way to do it
//c way
float fr=atof(fc); //this is a c way to do it
}