TEAM-ADA Archives

Team Ada: Ada Programming Language Advocacy

TEAM-ADA@LISTSERV.ACM.ORG

Options: Use Forum View

Use Proportional Font
Show Text Part by Default
Condense Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Sender:
"Team Ada: Ada Advocacy Issues (83 & 95)" <[log in to unmask]>
Subject:
From:
John McCormick <[log in to unmask]>
Date:
Wed, 3 Mar 1999 08:01:41 -0600
Content-Type:
TEXT/PLAIN; charset=US-ASCII
MIME-Version:
1.0
Reply-To:
John McCormick <[log in to unmask]>
Parts/Attachments:
TEXT/PLAIN (42 lines)
I thought you might enjoy this recent post by Cay Horstmann to the
Advanced Placement in Computer Science list.

John

-------------------------------------------------------
John W. McCormick                [log in to unmask]
Computer Science Department      [log in to unmask]
University of Northern Iowa      voice  (319) 273-2618
Cedar Falls, IA  50614-0507      fax    (319) 273-7123


---------- Forwarded message ----------

How do you print a floating-point number with field width 10 and two digits
after the decimal point, using only the standard library?

C
   printf("%10.2f", x);


C++
   cout << setw(10) << setprecision(2) << showpoint << x;


Java
   java.text.NumberFormat formatter
      = java.text.NumberFormat.getNumberInstance();
   formatter.setMinimumFractionDigits(2);
   formatter.setMaximumFractionDigits(2);
   s = formatter.format(x);
   for (int i = s.length(); i < 10; i++)
      System.out.print(' ');
   System.out.print(s);


Cay
Cay S. Horstmann

mailto:[log in to unmask]    Phone: 408/865-1895    10411 Flora Vista Ave.
http://www.horstmann.com    FAX:   408/865-0369    Cupertino, CA 95014

ATOM RSS1 RSS2