I use Mbed studio 1.0.0 with mbed-os 6.1.0 (win10 64bit)
Simple program returns %f instead of 1.2345
printf("%f \n" , 1.2345);
%s , %d seems work well ! Generating the same program via online editor works well too !
Board : stm32f103RB
To reduce the code size Mbed introduced Minimal printf and snprintf. As of Mbed OS 6.0 it is enabled by default. Floating point parameters are only present when
minimal-printf-enable-floating-point config is set to
true (disabled by default). I’m not sure but this could be the case when building with the online compiler. If your application requires more advanced functionality (at the cost of using more flash memory) you can switch to the standard printf library configuring it in
mbed_app.json file by overriding the parameter
target.printf_lib with the value
std as shown below:
For more details visit the link above .
Best regards, Zoltan
Thank You of course, it works !
Thanks so much for explaining this! There is 100% zero chance that I would have figured out why my floats keep coming out as %f without you.
As far as the developers who decided to disable printing floating point numbers by default, I think that was perhaps an overreach in terms of optimization.