How to print floating point numbers in a flash drive/ SD card using FAT File System?

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

How to print floating point numbers in a flash drive/ SD card using FAT File System?

1,614 次查看
Amit_Kumar1
Senior Contributor II

Hello all

I was going through the FATFS documentation and I came to know that we cannot print the floating point numbers using fprintf command in FATFS. But I wanted to print the floating values So How can I do that??

pastedImage_0.png

Thanks and Regards

Amit Kumar

标记 (3)
0 项奖励
回复
1 回复

960 次查看
egoodii
Senior Contributor III

For a 'limited range and scope' of 'floating point print' you can 'fake it' with integer operations.  Say you have an integer, say in this case one that represents milli-celsius (or a float, with slower math) so we always print exactly three digits after the decimal point:

     if( (temp < 0) && ((temp/1000) == 0) )

          printf("-");        //For our integer pseudo-float print, a zero-whole won't print '-' for us...

     printf(" %i.%03i degrees C\n",temp/1000,abs(temp)%1000);

Personally, I quickly gave up on this trick and opted to 'disable' the 'reduced function' printf from the example code sets and included the full-function compiler version, connecting the 'write' function to my console output.

0 项奖励
回复