Wed, 3 Mar 1999 09:28:37 -0500
|
> 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);
|
|
|