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

转自: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;
    }
时间: 2024-08-25 21:51:11

arduino:int & double 转string 适合12864下使用的相关文章

string 与 int double 的转化

#include <iostream> #include <string> #include <sstream> using namespace std; int main() { //string -> int float double string str = "088.123"; cout << "string -> int float double" << endl; cout <

c++ 中double与string之间的转换,char *

/* * main.cpp * * Created on: Apr 7, 2016 * Author: lizhen */ #include <iostream> //#include "MySqrt.h" #include <math.h> #include <vector> #include <typeinfo> #include <exception> #include <stdexcept> #includ

用C#.NET调用Java开发的WebService传递int,double问题,出现java无法获

用C#.NET调用Java开发的WebService传递int,double问题,出现java无法获得值! 用C#.NET调用Java开发的WebService时,先在客户端封装的带有int属性的对象,当将该对象传到服务器端时,服务器端可以得到string类型的属性值,却不能得到int类型.double和DateTime类型的值(在服务端得到的均为null) 解决办法: VS2005封装WebService引用 用C#.NET调用Java开发的WebService时,先在客户端封装的带有int属

C# 判断字符串是否是int/double

1 /// <summary> 2 /// 判断字符串是否是int/double 3 /// </summary> 4 public static bool IsIntOrDouble(string strNumber) 5 { 6 Regex objNotNumberPattern = new Regex("[^0-9.-]"); 7 Regex objTwoDotPattern = new Regex("[0-9]*[.][0-9]*[.][0-9

.build_release/lib/libcaffe.so: undefined reference to `cv::VideoCapture::set(int, double)&#39;

CXX/LD -o .build_release/tools/convert_imageset.bin.build_release/lib/libcaffe.so: undefined reference to `cv::VideoCapture::set(int, double)'.build_release/lib/libcaffe.so: undefined reference to `cv::VideoCapture::open(int)'//home/chenwending/anaco

第三题 有如下Student 对象, private String name; private int age; private int score; private String classNum; 其中,classNum 表示学生的班号,例如“class05”。 有如下List List list = new ArrayList();

list.add(new Student(“Tom”, 18, 100, “class05”)); list.add(new Student(“Jerry”, 22, 70, “class04”)); list.add(new Student(“Owen”, 25, 90, “class05”)); list.add(new Student(“Jim”, 30,80 , “class05”)); list.add(new Student(“Steve”, 28, 66, “class06”));

Java-集合-第三题 有如下Student 对象, private String name; private int age; private int score; private String classNum; 其中,classNum 表示学生的班号,例如“class05”。 有如下List List list = new ArrayList(); l

第三题 有如下Student 对象, private String name; private int age; private int score; private String classNum; 其中,classNum 表示学生的班号,例如“class05”. 有如下List List list = new ArrayList(); list.add(new Student(“Tom”, 18, 100, “class05”)); list.add(new Student(“Jerry”,

C#,int转成string,string转成int

转载:http://www.cnblogs.com/xshy3412/archive/2007/08/29/874362.html 1,int转成string用toString 或者Convert.toString()如下 例如:int varInt = 1; string varString = Convert.ToString(varInt); string varString2 = varInt.ToString(); 2,string转成int如果确定字符串中是可以转成数字的字符,可以用

C++ double转string类型以及MFC控件简单用法

这两天项目需要,测试c++库里面内容.生成jar再给Android调用.我没有学过C++,现在开始记录C++简单用法.测试时候一般都是使用mfc程序来测试,要输入值,显示结果吗.我用的编译环境vs2008. 一.double 转string #include <string> CString strResultx; strResultx.Format(_T("x:%.4f\n"), 89.7887878); 转换结果还是放在strResultx 2.两个字符串相连 CStr