当前位置:网站首页>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);
}
}
}
边栏推荐
猜你喜欢

自监督论文阅读笔记 DenseCL:Dense Contrastive Learning for Self-Supervised Visual Pre-Training

经典论文-ResNet

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

mysql 客户端SSL错误2026 (HY000)

自监督论文阅读笔记 Self-supervised Learning in Remote Sensing: A Review

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

自监督论文阅读笔记 Self-Supervised Deep Learning for Vehicle Detection in High-Resolution Satellite Imagery

寄存器常见指令

Convolutional Nerual Nertwork(CNN)

自监督论文阅读笔记Reading and Writing: Discriminative and Generative Modelingfor Self-Supervised Text Recogn
随机推荐
[Rebound shell and privilege escalation]
Execute the mysql script file in the docker mysql container and solve the garbled characters
Invalid signature file digest for Manifest main attributes解决方法
自监督论文阅读笔记 SimCLRV2 Big Self-Supervised Models are Strong Semi-Supervised Learners
自监督论文阅读笔记 Incremental-DETR:Incremental Few-Shot Object Detection via Self-Supervised Learning
ucos任务调度原理
MMU 介绍-[TBL/page table work]
block底层探索
Hook初探索
中国水环境治理行业投融资分析及“十四五”规划建议报告2022~2028年
Mysql 存储过程详解(procedure)
Makefile
Kettle Spoon 安装配置详解
KASLR-内核地址空间布局随机化
The ` monorepo ` ` hoist ` mechanism lead to the change of the loading configuration file path
寄存器常见指令
C# 数组之回溯法
用户登录验证程序的实现
自监督论文阅读笔记 Self-supervised Label Augmentation via Input Transformations
自监督论文阅读笔记DisCo: Remedy Self-supervised Learning on Lightweight Models with Distilled Contrastive