Mbed minimal-printf not padding format

Hi all!

I started porting over my mbed-os-5.15 project to mbed-os-6, and my printf statements started not to work as intended.

I see that mbed-os-6 switched to using their minimal-printf lib by default, and switching back to std fixes things for me.

However I would prefer the ROM savings with minimal-printf.

This brings me to my issue, a simple printf statement such as this:

sprintf(str, "Op: %04x", _op);

is no longer padding the hexadecimal value with zero’s as it does with the std printf lib.

I get something like this:

"Op: 4"

rather than this:

"Op: 0004"

Poking through the source code, it doesn’t appear like this feature is part of the config, and is global behavior for the library.

Any help would be appreciated to get this set up!

I’m having trouble with printf on display lib justification doesn’t work anymore.

int t = 20;
tft.printf("%3d", t);
//it should display like " 20" but it now displays like "20"

my workaround

int t = 20;
tft.printf(temp >= 100 ? "%i" : temp >= 10 ? " %i" : "  %i", t);

any better ideas are welcome

edit: I noticed now debug() is not working properly I can’t do things like %.2f

Just in case you are not aware of it… If you are okay with increased ROM usage, you can switch back to the standard library by overriding the parameter in mbed_app.json.

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

More info here:


@lonesometraveler wow, I discovered this just now :smiley: I was going to post, but you already post solution !

Thanks m8!

just an idea: it would be great if we could have a thread with workarounds for using minimal printf lib

Yes, that is what @pattyolanterns wanted to discuss. If I come up with a good idea, I will post it here.

also +1 for adding the padding :slight_smile: