How to fix mbed printf() printing literal %f in PlatformIO
Problem:
You are using code like
printf("%f\n", myFloat);
in your mbed/PlatformIO application, but instead of printing myFloat
it prints literal %f
.
Solution
mbed uses the minimal-printf
library by default which is configured to save space on the Microcontroller. Hence, float support (i.e. %f
support) is disabled by default. You need to enable it by adding mbed_app.json
in the root directory of the PlatformIO project with "platform.minimal-printf-enable-floating-point": true
:
{
"target_overrides": {
"*": {
"platform.minimal-printf-enable-floating-point": true
}
}
}
See the platform configuration option page for more details and similar options.