aligning decimal points?

This is a discussion on aligning decimal points? within the C Programming forums, part of the General Programming Boards category; Im new to c programing and am in a class to learn. our first project we have to create a ...

  1. #1
    Registered User
    Join Date
    Jan 2013
    Posts
    1

    aligning decimal points?

    Im new to c programing and am in a class to learn.

    our first project we have to create a program that allows a user to input their time worked hours pays and a deduction and then have the program display all their taxes and gross / net pay.

    that much I have done but for full credit we must make all the decimal points line up. what would be the best way to do this?

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Use the format specifiers for printf(). In particular the field width and resolution specifications:
    Code:
    printf("%10.2f\n",1234.5);
    printf("%10.2f\n",67.89);
    Makes a fleld 10 digits wide (the dot counts as 1 width), and displays your floating point number to 2 decimal places. You can change the position of the numbers inside the field width, by using the - before the field width specifier: %-10.2f etc.

  3. #3
    Registered User loserone+_+'s Avatar
    Join Date
    Dec 2012
    Location
    Indonesia
    Posts
    112
    yeah adak was right
    u can doing this on int and other declaring variables too
    like this
    Code:
    int a,b;
    char c,*d;
    float e;
    printf("%10d",a);
    printf("%10i",b);
    printf("%10c",c);
    printf("%10.1f",e);
    printf("%10s",d);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. output formatting (aligning decimal point)
    By slee8251 in forum C Programming
    Replies: 3
    Last Post: 02-04-2012, 03:38 PM
  2. fwrite and decimal points
    By george7378 in forum C++ Programming
    Replies: 1
    Last Post: 04-23-2011, 07:56 PM
  3. Decimal Points and Binary Points
    By Shadow12345 in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 11-07-2002, 01:06 AM
  4. (C++) How to detect decimal points?
    By jeffcoulter in forum C++ Programming
    Replies: 6
    Last Post: 10-17-2002, 03:36 PM
  5. decimal points
    By canine in forum Windows Programming
    Replies: 1
    Last Post: 04-29-2002, 11:01 PM

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