当前位置:网站首页>double型数据转字符串后通过MCU串口发送
double型数据转字符串后通过MCU串口发送
2022-08-03 05:24:00 【langaopeng】
double型数据转字符串如下函数,函数的功能如:将 double=12.123的数据转为CString = "12.123";后通过串口发出
void PutDataTOChar(double dat)
{
u8 i;
u8 tab[10];//存整数部分
u8 bot[6];//存小数部分
u8 iIndex =0;//整数部分指针
u8 jIndex =0;//小数部分指针
int aa = 0;
double pot = 0.0;
for(i=0;i<10;i++)
{
tab[i] = ' ';
bot[i] = ' ';
}
aa = (int) dat;//取整数
if(aa < 0) //是负数//
{
dat = -dat;
aa = -aa;
pot = dat-aa;
while(aa/10 > 0)//将int 型转为字符型
{
tab[iIndex++] = aa%10; // 取出个位
aa /= 10;
}
tab[iIndex] = aa;
for(i=0;i<5;i++)//将小数部分转为字符型
{
bot[jIndex++] = (int)(pot*10);
pot = pot*10 - (int)(pot*10);
}
putchar('-');
for(i=iIndex;i>0;i--)
{
putchar(tab[i]+0x30);
}
putchar(tab[i]+0x30);
putchar('.');
for(i=0;i<jIndex;i++)
{
putchar(bot[i]+0x30);
}
}
else
{
while(aa/10 > 0)
{
tab[iIndex++] = aa%10; // 取出个位
aa /= 10;
}
tab[iIndex] = aa;
for(i=0;i<5;i++)
{
bot[jIndex++] = (int)(pot*10);
pot = pot*10 - (int)(pot*10);
}
for(i=iIndex;i>0;i--)
{
putchar(tab[i]+0x30);
}
putchar(tab[i]+0x30);
putchar('.');
for(i=0;i<jIndex;i++)
{
putchar(bot[i]+0x30);
}
}
}
边栏推荐
猜你喜欢

自监督论文阅读笔记 S3Net:Self-supervised Self-ensembling Network for Semi-supervised RGB-D Salient Object Det

经典论文-ResNet

ucos任务调度原理

Kettle 从资源库中载入新的转换出错(Invalid byte 1 of 1-byte UTF-8 sequence)

Sqli-labs-master shooting range 1-23 customs clearance detailed tutorial (basic)

自监督论文阅读笔记 Self-supervised Label Augmentation via Input Transformations

自监督论文阅读笔记 Incremental-DETR:Incremental Few-Shot Object Detection via Self-Supervised Learning

Execute the mysql script file in the docker mysql container and solve the garbled characters

嵌入式实验四

深度学习基本概念
随机推荐
[CSRF, SSRF, XXE, PHP deserialization, Burpsuite]
【源码解读】火爆的二舅币真的跑路了吗?
优雅的拦截TabLayout的点击事件
[Rebound shell and privilege escalation]
自监督论文阅读笔记: MoCoV2使用动量对比学习改进基线
block底层探索
设备树(devicetree)-dts语法
HANA 常用数据类型详解
中国生物反应器行业发展现状及前景规划分析报告报告2022~2028年
神经网络基础
【Yarn】yarn常用命令 查看日志和Kill任务
page fault-页异常流程
【DC-4 Range Penetration】
东南亚跨境电商
Playing with Markdown(2) - Extraction and Manipulation of Abstract Syntax Trees
极光推送 能否缓存 消息
自监督论文阅读笔记 Multi-motion and Appearance Self-Supervised Moving Object Detection
中国聚氯乙烯(PVC)土工膜发展动态及投资前景预测报告2022~2028年
进程间通信IPC - 信号量
Qlik Sense 字符串截取和拼接详解(Left、Right、&)