Author Topic: Making the decimal points line up..  (Read 1451 times)

Offline docnascar

  • Sr. Member
  • ****
  • Posts: 465
Making the decimal points line up..
« on: March 15, 2011, 05:16:11 PM »
Me again!


Code: [Select]
#include <stdio.h>

int main()

{
    double y1, y2, y3;   
       
    //make the data rows LINE UP.... HOW??????? HOW???????????
    y1=99.5;
    y2=9.5;
    y3=999.5;
    printf ("%4.2lf\t%4.2lf\t%4.2lf\n",y1,y2,y3);   
   
    y1=999.5;
    y2=99.5;
    y3=9.5;
    printf ("%4.2lf\t%4.2lf\t%4.2lf\n",y1,y2,y3);   

    getchar ();
    getchar ();
 
    return 0;
}


This shows:
Code: [Select]
99.50   9.50    999.50
999.50  99.50   9.50

How do I make the decimal points line up? I guess I want the numbers to right justify???

Its hard to show on the message board.

  2.0   2.0
20.0 20.0
My main PCLINUXOS PC:
KDE Mini
AMD FX-6300 (3.5G / 6 core)
MSI 970A-G46 AM3+ MOBO
G.SKILL Sniper Series 8GB (2 x 4GB) 1866 (PC3 14900)
ECS GeForce GT 440 (Fermi) 512MB 128-bit GDDR5
Seagate Barracuda ST1000DM003 1TB 7200 RPM SATA
SAMSUNG DVD Burner SATA Model SH-224BB
POWERUP PU-550 (550W) p

Offline AS

  • Hero Member
  • *****
  • Posts: 4111
  • Have a nice ... night!
Re: Making the decimal points line up..
« Reply #1 on: March 15, 2011, 05:22:35 PM »
Quote
Me again!

me too!  ;D

printf ("%4.2lf\t%4.2lf\t%4.2lf\n",y1,y2,y3)

in the above statement, the 4 is the minimum amount of space, but your numbers are longer, use 7 instead of 4.
(4 digits + 1 decimal place + 2 decimal digits = 7)

AS

Offline docnascar

  • Sr. Member
  • ****
  • Posts: 465
Re: Making the decimal points line up..
« Reply #2 on: March 15, 2011, 05:26:44 PM »
Your awesome. Thanks again.


You must be addicted to this board. Your always here when I need you!

 ;D

Time for dinner. I'm hungry.
My main PCLINUXOS PC:
KDE Mini
AMD FX-6300 (3.5G / 6 core)
MSI 970A-G46 AM3+ MOBO
G.SKILL Sniper Series 8GB (2 x 4GB) 1866 (PC3 14900)
ECS GeForce GT 440 (Fermi) 512MB 128-bit GDDR5
Seagate Barracuda ST1000DM003 1TB 7200 RPM SATA
SAMSUNG DVD Burner SATA Model SH-224BB
POWERUP PU-550 (550W) p