字符串.toInt()转换成整型
字符串.toFloat() 转换成Float类型
使用String()转换整型等其他的类型
可以转换成字符串的类型:可以转换的类型,string、char、byte、int、long、unsigned int、unsigned long、float、double。
//官方文档:https://www.arduino.cc/reference/en/language/variables/data-types/stringobject/
代码
void setup()
{
// put your setup code here, to run once:
//可以转换成字符串的类型:可以转换的类型,string、char、byte、int、long、unsigned int、unsigned long、float、double。
//官方文档:https://www.arduino.cc/reference/en/language/variables/data-types/stringobject/
Serial.begin(9600);
//字定义需要转换的字符串数据
String my_str = "12345.123";
//字符串转换成整型数据;
int my_int = my_str.toInt();
Serial.println(my_int);
//字符串转换成Float类型
Serial.println(my_str.toFloat());
//整型转换成字符串,
int ty = 1000;
String mystr=String(ty);
Serial.println(mystr+mystr);
}
void loop()
{
// put your main code here, to run repeatedly:
}