-->
Page 2 of 2

Re: (s)printf not working WRT '%.'

PostPosted: Mon Dec 03, 2018 5:23 pm
by btidey
For integers %nd prints with n characters and uses leading spaces.

If you want leading zeros then use %0nd where n is the total characters

So %02d should do what you want.

Re: (s)printf not working WRT '%.'

PostPosted: Mon Dec 03, 2018 6:17 pm
by FreddyVictor
Ah - thank you!
Yes, that does work, albeit not to the c/c++ standard
I see souces in the ESP directories using the correct '%.' specifier, so somethings broke ...

Re: (s)printf not working WRT '%.'

PostPosted: Tue Dec 04, 2018 4:21 am
by btidey
The %02d is OK in C, C++ The first character after the % can be a flag

nothing = pad with spaces
- left justify
+ display sign
0 pad with zeros

See https://en.wikipedia.org/wiki/Printf_format_string

The main arduino printf implementation has been weak for floating point which I guess is why the precision . version is problematic.