TEAM-ADA Archives

Team Ada: Ada Programming Language Advocacy

TEAM-ADA@LISTSERV.ACM.ORG

Options: Use Classic View

Use Proportional Font
Show HTML Part by Default
Show All Mail Headers

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

Print Reply
"W. Wesley Groleau x4923" <[log in to unmask]>
Wed, 3 Mar 1999 09:28:37 -0500
text/plain (33 lines)
> I thought you might enjoy this recent post by Cay Horstmann to the
> Advanced Placement in Computer Science list.

Let's include Ada in chronological order:

> 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);
>
>
> Ada
>    Put (Item => X,
>         Fore => 7,  -- width = Fore + Aft + 1 (the point)
>         Aft  => 2,
>         Exp  => 0);
>
>
> 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);

ATOM RSS1 RSS2