formatting numbers

michael montagne montagne at boora.com
Mon Jun 4 19:00:10 EDT 2001


Thank you all.  I knew there was a simple way.

-mjm
  "Ken Seehof" <kens at sightreader.com> wrote in message news:mailman.991688947.28483.python-list at python.org...
  >>> num = 49
  >>> print "%05d" % num
  00049

  The % operator is popular for C/C++ programmers like me, who are
  used to the standard library C function "printf".  Otherwise you may
  prefer a somewhat more pythonic approach:

  >>> print ("0000" + `num`)[-5:]  # works for num >= 0
  00049


  ----- Original Message -----
  From: "michael montagne" <montagne at boora.com>
  Newsgroups: comp.lang.python
  To: <python-list at python.org>
  Sent: Monday, June 04, 2001 1:21 PM
  Subject: formatting numbers


  > Simple question.  I am accessing a database of job numbers that take the
  > form of "00049" and "01049".  These values are integers.  When I return
  the
  > value from the database it reads "49".  I need to add the leading digits
  if
  > they are there so this number would read "00049".  In MSAccess I used
  > Format(num,"00000").  How can I do that with Python?
  >
  > -mjm
  >
  >
  >
  > --
  > http://mail.python.org/mailman/listinfo/python-list

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20010604/27752de1/attachment.html>


More information about the Python-list mailing list