TEAM-ADA Archives

Team Ada: Ada Programming Language Advocacy

TEAM-ADA@LISTSERV.ACM.ORG

Options: Use Forum View

Use Monospaced Font
Show HTML 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:
"W. Wesley Groleau x4923" <[log in to unmask]>
Date:
Wed, 3 Mar 1999 09:28:37 -0500
X-To:
Reply-To:
"W. Wesley Groleau x4923" <[log in to unmask]>
Parts/Attachments:
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