Arm Mbed OS support forum

Float Printf() doesnt work in desktop version

Hi,

I use Mbed studio 1.0.0 with mbed-os 6.1.0 (win10 64bit)

Simple program returns %f instead of 1.2345

int main()
{

while(1) 

{

   printf("%f \n" , 1.2345);
   ThisThread::sleep_for(WAIT_MS);
}

}

%s , %d seems work well ! Generating the same program via online editor works well too !
Board : stm32f103RB

Hello Laszlo,

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:

    "target_overrides": {
        "*": {
            "target.printf_lib": "std"
        }
    }

For more details visit the link above .

Best regards, Zoltan

2 Likes

Hello Zoli,

Thank You of course, it works !

Laci

Zoltan,

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.

Thank you,
Dave

1 Like