首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

ASCII 字符串转换为 double 值解决方案

2012-01-11 
ASCII字符串转换为 double 值大家好:小弟用SerialPort.ReadByte()读取COM1的一组ASCII字符.保存到buff(int

ASCII 字符串转换为 double 值
大家好:

      小弟用   SerialPort.ReadByte()   读取COM1   的一组ASCII字符.保存到   buff
(int   []   buff   =   new   int[8]   )

        内容为     buff   =   "   128.66   "     //   ASCII   字符串

        请问怎样将这个字符串转为   double   的   128.66   值呢?   谢谢!

[解决办法]
char[] buff = new char[] { '1 ', '2 ', '8 ', '. ', '6 ', '6 ' };
string s = new string(buff);

double d = double.Parse(s);

*****************************************************************************
欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码)

最新版本:20070212

http://www.cnblogs.com/feiyun0112/archive/2006/09/20/509783.html
[解决办法]
char[] buffer = new char[8];
//SerialPort.ReadByte() int是4个字节并不是byte,ReadByte用char更好
string str = new string(buffer);
double d = double.Parse(str);
[解决办法]
byte[] buff = new byte[8];
//用byte[]这样处理
double.Parse(Encoding.ASCII.GetString(buff));

热点排行