Shop OBEX P1 Docs P2 Docs Learn Events
C: %5.2f within a print command, proceeded by extra space — Parallax Forums

C: %5.2f within a print command, proceeded by extra space

idbruceidbruce Posts: 6,197
edited 2015-04-22 13:02 in Propeller 1
I do not know if this is the norm, but if you use %5.2f within a print command, the data is proceeded by a space.

I don't believe it would be the norm, so I am mentioning it as a heads up :)

However, my assumption could be wrong :)

Comments

  • ersmithersmith Posts: 6,053
    edited 2015-04-22 11:56
    %5.2f has an explicit field with of 5 and precision of 2. If your number doesn't need that much room, it will be padded on the left with spaces. If you want it padded with 0 instead, use %05.2f. If you don't want any padding, don't give a field width (so just %.2f). This is the documented behavior of printf, which is covered in many places (both online and in books on C).
  • idbruceidbruce Posts: 6,197
    edited 2015-04-22 12:33
    ersmith
    %5.2f has an explicit field with of 5 and precision of 2. If your number doesn't need that much room, it will be padded on the left with spaces. If you want it padded with 0 instead, use %05.2f. If you don't want any padding, don't give a field width (so just %.2f). This is the documented behavior of printf, which is covered in many places (both online and in books on C).

    My bad. I really haven't done that much formatting in the past, except for time based strings. However as you point out, I am sure there is plenty of documentation. As much as I hate to admit it, programming microcontrollers is in many ways more complicated than writing a Windows program. There is so much to learn.

    The %.2f format worked great. Thank you.
  • DavidZemonDavidZemon Posts: 2,973
    edited 2015-04-22 13:02
    ersmith wrote: »
    If you don't want any padding, don't give a field width (so just %.2f)

    Didn't know that. Thanks :)
Sign In or Register to comment.