Thread: Displaying zeros

  1. #1
    Registered User
    Join Date
    Mar 2008

    Displaying zeros


    I am fairly new to programming. Can anyone help me in getting it to display zeros to the left of a decimal point? For example, instead of displaying 5 show as 005?

  2. #2
    Registered User
    Join Date
    Jan 2008
    Set the fill for cout to be whatever character you want. Then when you have a width longer than the length of the value, empty space will be repaced with that character.
    #include <iomanip>
    #include <iostream>
    using namespace std;
    int main()
        double a = 5.0;
        int b = 5;
        cout << setw(3) << a << endl;
        cout << setw(3) << b << endl;
        return 0;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 12
    Last Post: 04-12-2009, 05:49 PM
  2. leading zero's..... ( reading int )
    By sh4k3 in forum C Programming
    Replies: 4
    Last Post: 06-12-2007, 09:03 AM
  3. Need Help Displaying A Pattern.
    By slickwilly440 in forum C++ Programming
    Replies: 4
    Last Post: 10-05-2005, 11:01 AM
  4. Displaying all zeros?
    By musayume in forum C Programming
    Replies: 2
    Last Post: 02-04-2002, 07:51 PM
  5. Need codes for displaying figures in descending mode.
    By rbaba in forum C++ Programming
    Replies: 0
    Last Post: 12-14-2001, 07:47 PM
Website Security Test