Right-Justifying Numeric Output

Discussion in 'Python' started by hg, Jan 25, 2007.

  1. hg

    hg Guest

    Rich Shepard wrote:

    > I have this print statement in a function:
    >
    > print '%2d $%11.2f $%10.2f $%9.2f $%9.2f' %(nper, pv, diff, ten,
    > bonus)
    >
    > and I would like to have the output right justified in the specified
    > field. My trials using .rjust(n) have produced that string in the output,
    > not the intended results. Is there a way of right justifying numeric
    > output?
    >
    > Thanks,
    >
    > Rich
    >
    > --
    > Richard B. Shepard, Ph.D. | The Environmental Permitting
    > Applied Ecosystem Services, Inc. | Accelerator(TM)
    > <http://www.appl-ecosys.com> Voice: 503-667-4517 Fax:
    > 503-667-8863


    assuming max size = 10

    #with spaces
    >> '% 10d' % 11

    ' 11'
    #with zeros
    >>'%010d' % 11

    '0000000011'

    hg
    hg, Jan 25, 2007
    #1
    1. Advertising

  2. hg

    Rich Shepard Guest

    I have this print statement in a function:

    print '%2d $%11.2f $%10.2f $%9.2f $%9.2f' %(nper, pv, diff, ten, bonus)

    and I would like to have the output right justified in the specified field.
    My trials using .rjust(n) have produced that string in the output, not the
    intended results. Is there a way of right justifying numeric output?

    Thanks,

    Rich

    --
    Richard B. Shepard, Ph.D. | The Environmental Permitting
    Applied Ecosystem Services, Inc. | Accelerator(TM)
    <http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863
    Rich Shepard, Jan 25, 2007
    #2
    1. Advertising

  3. hg

    Rich Shepard Guest

    On Thu, 25 Jan 2007, hg wrote:

    > assuming max size = 10
    >
    > #with spaces
    >>> '% 10d' % 11

    > ' 11'
    > #with zeros
    >>> '%010d' % 11

    > '0000000011'


    Thank you very much! I didn't see this in any of my Python books or on the
    Web.

    Rich

    --
    Richard B. Shepard, Ph.D. | The Environmental Permitting
    Applied Ecosystem Services, Inc. | Accelerator(TM)
    <http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863
    Rich Shepard, Jan 25, 2007
    #3
  4. hg

    Tobiah Guest


    > Thank you very much! I didn't see this in any of my Python books or on
    > the


    I like to look at the printf docs for any C compiler. On Unix,
    man 3 printf


    --
    Posted via a free Usenet account from http://www.teranews.com
    Tobiah, Jan 25, 2007
    #4
  5. At Thursday 25/1/2007 19:34, Rich Shepard wrote:

    > > assuming max size = 10
    > >
    > > #with spaces
    > >>> '% 10d' % 11

    > > ' 11'
    > > #with zeros
    > >>> '%010d' % 11

    > > '0000000011'

    >
    > Thank you very much! I didn't see this in any of my Python books or on the
    >Web.


    http://docs.python.org/lib/typesseq-strings.html


    --
    Gabriel Genellina
    Softlab SRL






    __________________________________________________
    Preguntá. Respondé. Descubrí.
    Todo lo que querías saber, y lo que ni imaginabas,
    está en Yahoo! Respuestas (Beta).
    ¡Probalo ya!
    http://www.yahoo.com.ar/respuestas
    Gabriel Genellina, Jan 26, 2007
    #5
    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. Swetha
    Replies:
    4
    Views:
    976
    Swetha
    Feb 5, 2006
  2. Tom Parson
    Replies:
    1
    Views:
    493
    Daniel Dyer
    May 23, 2006
  3. Replies:
    5
    Views:
    909
    X-Centric
    Jun 30, 2005
  4. mantrid

    Text box justifying

    mantrid, Jan 4, 2008, in forum: HTML
    Replies:
    2
    Views:
    366
    mantrid
    Jan 4, 2008
  5. Ronny
    Replies:
    0
    Views:
    137
    Ronny
    May 5, 2006
Loading...

Share This Page