Skip to main content
Associate III
May 17, 2025
Solved

printf fail to print float type

  • May 17, 2025
  • 3 replies
  • 574 views

Software tool: IAR Workbench 9.60

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <intrinsics.h>

int putchar( int ch ){  
  while(!(USART2->ISR&0X0080));   
USART2->TDR  = (unsigned char)ch;
return ch;
}
 
test code:
printf("%d\n",ADC_array[0]);
printf("%f\n",1.234567);
 
Output on computer:
62615       ----correct
%f             ----incorrect(should output 1.234567)
This topic has been closed for replies.
Best answer by AScha.3

check : project->properties->settings : use float with printf...

AScha3_0-1747501069208.png

 

3 replies

Tesla DeLorean
Guru
May 17, 2025

Perhaps need to check box full scanf/printf libraries supporting floating point.

Likely quite large so not enabled by default.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
AScha.3
AScha.3Best answer
Super User
May 17, 2025

check : project->properties->settings : use float with printf...

AScha3_0-1747501069208.png

 

If you feel a post has answered your question, please click on " Best Answer ".
STM32L09Author
Associate III
May 18, 2025

thank you, I found it in this window:

STM32L09_0-1747530336194.png

the default is Small, I change it to Full, now it works, I have float printed.

63445
1.234567

 

by the way, will this configuration increase the hex fill? should I change it back to Small after debugging? so I can save the flash size.