decimal alignment

This is a discussion on decimal alignment within the C++ Programming forums, part of the General Programming Boards category; help! I need to align decimal places of my output that's printed in fixed notation to 5 decimal places!! I ...

  1. #1
    Registered User scuba22's Avatar
    Join Date
    Oct 2002
    Posts
    35

    decimal alignment

    help!
    I need to align decimal places of my output that's printed in fixed notation to 5 decimal places!!
    I used this:
    /*
    double a =1.0000
    printf ("\t\t\t\t%8.3f\n", a
    */
    but it only took the precision to 3, and when i changed the 8.3 to 8.5 it was't lined up....
    ahhhhhhhh

    can anyone point me at the correct code?
    Thanks

    scuba22

  2. #2
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    cout <<setiosflags (ios::showpoint | ios::fixed | ios::right | setprecision(number));

    thats the way i know how to do it

  3. #3
    Registered User scuba22's Avatar
    Join Date
    Oct 2002
    Posts
    35
    this is the error i get....
    - the numbers still aren't aligning
    i am using


    #include<iostream>
    #include<iomanip>
    using namespace std;



    is there another header i am missing????

    (Ihave been at this for 4 hours)
    just trying to align my silly output, ready to split in2 :-(
    scuba22

  4. #4
    Registered User scuba22's Avatar
    Join Date
    Oct 2002
    Posts
    35
    the error:
    sorry-

    C:\Program Files\Microsoft Visual Studio\MyProjects\HW_926a\HW_926a.cpp(15) : error C2677: binary '|' : no global operator defined which takes type 'struct std::_Smanip<int>' (or there is no acceptable conversion)

  5. #5
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    think its my fault, wrong syntax: here ya go try this:

    cout <<setiosflags (ios::fixed | ios::showpoint | ios::right) <<setprecision(number)

    not missing a header, that had to of been why it yelled but the pipe char |

  6. #6
    Registered User scuba22's Avatar
    Join Date
    Oct 2002
    Posts
    35
    thanks for trying --it's still not right jusified....
    what i want to do is align output's decimal points...
    it's so not happening.
    the program calculates circumference, area, volume, surface area of a circle/sphere....to 5 decimal places....
    and i cannot got those decimals lined up!

  7. #7
    Registered User
    Join Date
    Sep 2002
    Posts
    72
    you need setw(number) to create a right margin. This goes on the same line like this:

    Code:
    cout<<setw(10)<<var1;
    cout<<setw(10)<<radius;

  8. #8
    Registered User scuba22's Avatar
    Join Date
    Oct 2002
    Posts
    35
    THANKS...with alittle modification it's working!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I need help with decimal to binary Algorithm
    By webznz in forum C Programming
    Replies: 4
    Last Post: 03-13-2008, 04:52 AM
  2. Replies: 28
    Last Post: 07-17-2006, 12:35 AM
  3. hex to binary,hex to decimal
    By groovy in forum C Programming
    Replies: 2
    Last Post: 01-25-2006, 02:14 AM
  4. Confused by expression.
    By Hulag in forum C Programming
    Replies: 3
    Last Post: 04-07-2005, 08:52 AM
  5. decimal to binary, decimal to hexadecimal and vice versa
    By Unregistered in forum C++ Programming
    Replies: 9
    Last Post: 12-08-2001, 11:07 PM

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