当前位置:网站首页>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);
}
}
}
边栏推荐
- 【HQL】(一)json字符串处理json_tuple和get_json_object
- 【Yarn】yarn常用命令 查看日志和Kill任务
- Browser multi-threaded off-screen rendering, compression and packaging scheme
- Qlik Sense 临时处理表数据详解(Resident)
- 极光推送 能否缓存 消息
- 布尔盲注需简化代码
- 【DC-5 Range Penetration】
- 嵌入式实验四
- Kettle Spoon 安装配置详解
- Execute the mysql script file in the docker mysql container and solve the garbled characters
猜你喜欢

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

二叉树常见的问题和解决思路

KASLR-内核地址空间布局随机化

A.1#【内存管理】——1.1.3 page: struct page

The ` monorepo ` ` hoist ` mechanism lead to the change of the loading configuration file path

寄存器常见指令

边缘辅助无人机网络的分层联邦学习

【IDEA】字体修改-护眼主题-文件注释头设置

Let small program development into ` tailwind jit ` era

【第三周】ResNet+ResNeXt
随机推荐
A.1#【内存管理】——1.1.3 page: struct page
边缘辅助无人机网络的分层联邦学习
自监督论文阅读笔记Index Your Position: A Novel Self-Supervised Learning Method for Remote Sensing Images Sema
自监督论文阅读笔记SELF-SUPERVISED SPECTRAL MATCHING NETWORK FOR HYPERSPECTRAL TARGET DETECTION
时间盲注脚本
中国水环境治理行业投融资分析及“十四五”规划建议报告2022~2028年
【HQL】(二) 查询使用正则表达式做列选择
进程间通讯 (IPC 技术) - 信号
ASP.NET MVC:自定义 Route
中国生活垃圾处理行业十四五规划与投融资模式分析报告2022~2028年
二叉树常见的问题和解决思路
自监督论文阅读笔记 Multi-motion and Appearance Self-Supervised Moving Object Detection
自监督论文阅读笔记 DenseCL:Dense Contrastive Learning for Self-Supervised Visual Pre-Training
自监督论文阅读笔记DisCo: Remedy Self-supervised Learning on Lightweight Models with Distilled Contrastive
IPC通信 - 管道
A.1#【内存管理】——1.1.1 node:struct pglist_data
中国生产力促进中心”十四五”规划与发展规模分析报告2022~2028年
中国认证认可服务行业“十四五”发展规划及经营模式分析报告2022~2028年
设备树(devicetree)-dts语法
ARMv8 架构----armv8 类别