View previous topic :: View next topic |
Author |
Message |
kmp84
Joined: 02 Feb 2010 Posts: 382
|
printf, sprintf format |
Posted: Mon Dec 31, 2018 3:52 am |
|
|
Hello,
I want to use %X.Yw printf format with leading zeros. Can I do this?
For Example:
Code: |
unsigned int32 b = 12345;
printf("\r\nVar_b: %06.2lw", b); |
Thanks! |
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 19780
|
|
Posted: Mon Dec 31, 2018 4:38 am |
|
|
Yes,
However as posted, you won't get any zeros.
The count at the front of a C format specifier, is the _total field width_.
You are saying use 6 characters, with a decimal, and two trailing digits
So 123.45
This is six characters, so no space for a leading zero.
If you use: %09.2lw"
You will then get six digits in front of the decimal, so:
000123.45 |
|
 |
kmp84
Joined: 02 Feb 2010 Posts: 382
|
|
Posted: Mon Dec 31, 2018 6:46 am |
|
|
Hi Mr."Ttelmah",
Š¢hanks for the fix! My mistake was that not counting '.' for character!
Best Wishes! |
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 19780
|
|
Posted: Mon Dec 31, 2018 8:34 am |
|
|
That's quite a common slip...
Happy New Year everyone. |
|
 |
kmp84
Joined: 02 Feb 2010 Posts: 382
|
|
Posted: Mon Dec 31, 2018 9:13 am |
|
|
Happy New Year and The Best Wishes!  |
|
 |
|