printf() formatting - stripping zeroes, padding

Discussion in 'C++' started by Michal Prinke, Oct 19, 2004.

  1. Hello,

    Here are two questions on formatting values using printf():

    1. How to strip trailing zeroes from float values?
    printf("%f %f", 1.777, 1.2) displays "1.777000 1.200000",
    while I want to have "1.777 1.2", without loosing 6-digit
    precision.

    2. Is it possible to pad values with other characters than
    space and zero? printf(">%5s<", "abc") displays "> abc<".
    I would like to have e.g. ">##abc<" or ">--abc<".

    Thank you!
     
    Michal Prinke, Oct 19, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Piotr B.
    Replies:
    2
    Views:
    520
    CBFalconer
    Oct 19, 2004
  2. cjl
    Replies:
    11
    Views:
    834
    Bengt Richter
    Mar 26, 2005
  3. Michal Prinke

    printf() formatting - stripping zeroes, padding

    Michal Prinke, Oct 19, 2004, in forum: C Programming
    Replies:
    0
    Views:
    342
    Michal Prinke
    Oct 19, 2004
  4. Piotr B.
    Replies:
    4
    Views:
    690
    Piotr B.
    Oct 20, 2004
  5. pb
    Replies:
    15
    Views:
    11,327
    totoquebec
    Feb 6, 2012
Loading...

Share This Page