arduino:int & double 转string 适合12864下使用

简介: 转自:http://www.geek-workshop.com/forum.php?mod=viewthread&tid=3383&highlight=12864 很多人在玩12864的时候,都会发现不能直接显示字符,因为大多数12864类库没有显示数值的函数,那么我们就需要把int型变量转换成字...

转自:http://www.geek-workshop.com/forum.php?mod=viewthread&tid=3383&highlight=12864

很多人在玩12864的时候,都会发现不能直接显示字符,因为大多数12864类库没有显示数值的函数,那么我们就需要把int型变量转换成字符串,方法很简单,只要在代码末尾加上一个功能函数即可~

 

    char* itostr(char *str, int i)
    {
        sprintf(str, "%d", i); return str; }

 

把上述代码放入程序末尾,在程序头定义一个char a[25],在读取完数值之后就可以轻松的用一行itostr(a,b);来转换,其中a是之前定义的char,b是数值变量,是不是很方便呢?

======================================
附一个double转string的.

 

    void setup() {
      // put your setup code here, to run once:
      double test = 1.23; char test2[25] ; dtostr(test2,test); } void loop() { // put your main code here, to run repeatedly:  } char* dtostr(char *str, double d) { sprintf(str, "%f", d); return str; }

 

目录
相关文章
|
5月前
|
Go
go string to int 字符串与整数型的互换
go string to int 字符串与整数型的互换
34 0
|
22天前
|
NoSQL C++
c++中包含string成员的结构体拷贝导致的double free问题
c++中包含string成员的结构体拷贝导致的double free问题
8 0
|
1月前
|
C#
C# 字节数组与INT16,float,double之间相互转换,字符数组与字符串相互转换,
C# 字节数组与INT16,float,double之间相互转换,字符数组与字符串相互转换,
37 1
|
1月前
|
Python
Python系列(15)—— int类型转string类型
Python系列(15)—— int类型转string类型
|
6月前
|
存储 C语言
C 语言实例 - 计算 int, float, double 和 char 字节大小
C 语言实例 - 计算 int, float, double 和 char 字节大小。
35 1
|
6月前
|
Java
【Java用法】Java中String类型和int类型互转的所有方法
【Java用法】Java中String类型和int类型互转的所有方法
78 0
|
4月前
|
Python
TypeError: int() argument must be a string, a bytes原因
Python开发过程中,使用int()函数来转换或生成int类型的数据时,如果Python抛出并提示TypeError: int() argument must be a string, a bytes-like object or a real number, not 'complex',那么原因在于传递给int()函数的参数类型有误,正如TypeError的提示,int()函数的参数必须是string字符串(数值字符串)、类似字节对象、real number数字等,而不可以是complex复数类型的数据。
108 0
|
5月前
|
存储 C语言
计算 int, float, double 和 char 字节大小
C 语言实例 - 计算 int, float, double 和 char 字节大小。
44 1
|
8月前
对int,char,float,double进行求和操作
对int,char,float,double进行求和操作
102 0
|
8月前
|
Go
golang 中string和int类型相互转换
golang 中string和int类型相互转换
80 0