中级会员
 
- 积分
- 241
- 金钱
- 241
- 注册时间
- 2019-2-15
- 在线时间
- 38 小时
|
发表于 2019-2-15 18:04:46
|
显示全部楼层
我感觉就是对字符串的处理吧 把传输的数据字符串转换成整形或浮点型 然后再计算 大概是这样吧
Str2float.h
[mw_shl_code=applescript,true]#ifndef __Str2float_H
#define __Str2float_H
float Get_float(char c[],unsigned int len);
float Decimals_Deal(char c[],unsigned int p);
#endif[/mw_shl_code]
Str2float.c
[mw_shl_code=applescript,true]#include "Str2float.h"
#include "string.h"
unsigned int i = 0;
float Decimals_Deal(char c[],unsigned int q)
{
float ss = 0.1,result = 0;
for(i = q+1;i<strlen(c);i++)
{
result+=ss*c;
ss= ss*0.1;
}
return result;
}
float Integer_Deal(char c[],unsigned int k)
{
float temp = 0,s = 1;
for(i = 0;i<k;i++)
{
temp +=(float)c[k-i-1]*s;
s *= 10;
}
return temp;
}
float Get_float(char c[],unsigned int len)
{
unsigned int q = 0;
float a = 0;
for(i=0;i<len;i++)
{
if(c==0x2e)
{
q = i;
break;
}
}
for(i = 0;i<strlen(c);i++)
{
if(i!=q)
{
c = c-0x30;
}
}
switch(q)
{
case 0:
{
a += Decimals_Deal(c,q);
}break;
case 1:
{
a = Integer_Deal(c,q);
a += Decimals_Deal(c,q);
}break;
case 2:
{
a = Integer_Deal(c,q);
a += Decimals_Deal(c,q);
}
case 3:
{
a = Integer_Deal(c,q);
a += Decimals_Deal(c,q);
}
}
return a;
}
[/mw_shl_code] |
|