1552 views|0 replies

3836

Posts

19

Resources
The OP
 

Problems with using printf to print floating point numbers in a single chip microcomputer [Copy link]

For the single-chip microcomputer, the processing power is limited. I use stm32 to directly use the printf function (of course printf uses the serial port method), directly use printf ("xxxx=%f", xxxx), and the printed data is a long string of messy data.

In real-time applications, we usually write our own processing program. The question now is: how to output floating-point numbers to the display device more conveniently and quickly.

According to the method of netizens online, it is a good idea to extract the decimals:

void PrintFloat(float value)
{
int tmp,tmp1,tmp2;
tmp = (int)value;
tmp1=(int)((value-tmp)*10)%10;
tmp2=(int)((value-tmp)*100)%10;
printf("value=%d.%d%d\r\n",tmp,tmp1,tmp2);
}

This post is from Microcontroller MCU
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list