I am writing a C program for SAM3N arm cortex-M3 microcontroller. When I try to print float numbers, it just prints 'f'. 
Example: printf("%f",43.12); prints f only, not the 43.12.
But printing with integers works fine.
How to enable full printing of floats? I know that the compiler, by default, disabled float printing to reduce code size (i.e. seems, they linked cut-down version). Also please note that, there is no CFLAGS=-Dprintf=iprintf used in makefile.
Tools details:
Can you try, adding the below option in linker settings
-lc -lrdimon -u _printf_float
and it worked for me in ARM-CORTEXM0
It can be so that your platform/libs does not support %f format specifier for printf/sprintf.
As a first approach you can roll your own printf for floats/doubles:
void printDouble(double v, int decimalDigits)
{
  int i = 1;
  int intPart, fractPart;
  for (;decimalDigits!=0; i*=10, decimalDigits--);
  intPart = (int)v;
  fractPart = (int)((v-(double)(int)v)*i);
  if(fractPart < 0) fractPart *= -1;
  printf("%i.%i", intPart, fractPart);
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With