当前位置:网站首页>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);
}
}
}
边栏推荐
- Browser multi-threaded off-screen rendering, compression and packaging scheme
- page fault-页异常流程
- Qlik Sense 字符串截取和拼接详解(Left、Right、&)
- 中国人造金刚石行业投资战略规划及发展前景预测报告2022~2028年
- 自监督论文阅读笔记 Incremental-DETR:Incremental Few-Shot Object Detection via Self-Supervised Learning
- [CSRF, SSRF, XXE, PHP deserialization, Burpsuite]
- 中国水环境治理行业投融资分析及“十四五”规划建议报告2022~2028年
- 中国聚氯乙烯(PVC)土工膜发展动态及投资前景预测报告2022~2028年
- 代码没写完,哪里有脸睡觉!17 张程序员壁纸推荐
- 【 Nmap and Metasploit common commands 】
猜你喜欢

自监督论文阅读笔记SELF-SUPERVISED SPECTRAL MATCHING NETWORK FOR HYPERSPECTRAL TARGET DETECTION
![[frp intranet penetration]](/img/5c/ca18bef3e5fec279c19825ee93b34b.png)
[frp intranet penetration]

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

神经网络之感知机

Gradle插件与代理服务器导致Sync Project失败的问题

关于梯度下降法的一些优化方法

自监督论文阅读笔记 DetCo: Unsupervised Contrastive Learning for Object Detection

自监督论文阅读笔记 SimCLRV2 Big Self-Supervised Models are Strong Semi-Supervised Learners

经典论文-ResNet

Dynamic adjustment subject web system?Look at this one is enough
随机推荐
opencv
磁盘空间管理
漫谈Map Reduce 参数优化
Qlik Sense 字符串截取和拼接详解(Left、Right、&)
Invalid signature file digest for Manifest main attributes解决方法
Oracle count(1)、count(*)、count(列) 区别详解
微信小程序 自定义tabBar
设备树解析源码分析<devicetree>-1.基础结构
NFT租赁提案EIP-5006步入最后审核!让海外大型游戏的链改成为可能
观看华为AI技术领域课程--深度学习前三章总结
自监督论文阅读笔记 DetCo: Unsupervised Contrastive Learning for Object Detection
该描述怎么写成SQL语句
自监督论文阅读笔记Index Your Position: A Novel Self-Supervised Learning Method for Remote Sensing Images Sema
IPC通信 - 管道
Leetcode刷题——128. 最长连续序列
Qemu 搭建Armv8 平台
嵌入式实验三(代码几乎都要改才能运行)
[Rebound shell and privilege escalation]
Kettle 从资源库中载入新的转换出错(Invalid byte 1 of 1-byte UTF-8 sequence)
网络间通信