Printing 2 digits

This is a discussion on Printing 2 digits within the C Programming forums, part of the General Programming Boards category; Hello, using "%2d" print 2 digits, however when the digit is one number, the 0 is not printed, but is ...

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    27

    Printing 2 digits

    Hello,

    using "%2d" print 2 digits, however when the digit is one number, the 0 is not printed, but is left blank. How can I print 01, 02, 03 etc instead of 1, 2 , 3 etc....?

    Thanks

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Funnily enough, C actually gives you an intuitive way to do this, just use the %02d flag.
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Oct 2003
    Posts
    27
    Thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C# Printing Problem
    By silverlight001 in forum C# Programming
    Replies: 0
    Last Post: 03-23-2009, 01:13 AM
  2. decimal to number if digits in different bases
    By jorgejags in forum C Programming
    Replies: 21
    Last Post: 09-24-2008, 12:55 PM
  3. Printing a specific number of digits
    By JizJizJiz in forum C++ Programming
    Replies: 4
    Last Post: 06-28-2006, 08:14 PM
  4. need help relating printing?
    By omarlodhi in forum Linux Programming
    Replies: 0
    Last Post: 03-03-2006, 03:46 AM
  5. Hex digits stored in char array.
    By Kevinmun in forum C Programming
    Replies: 8
    Last Post: 11-18-2005, 03:05 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21