Seite 1 von 1

The March of Progress

Verfasst: So Jan 29, 2017 9:53 pm
von Xin
Ich werde ja gerne dafür kritisiert, dass ich bis heute gerne printf in C++ verwende...

The March of Progress, by Cay Horstmann

1980: C

Code: Alles auswählen

printf("%10.2f", x);
1988: C++

Code: Alles auswählen

cout << setw(10) << setprecision(2) << showpoint << x;
1996: Java

Code: Alles auswählen

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

Code: Alles auswählen

System.out.printf("%10.2f", x);
2008: Scala and Groovy

Code: Alles auswählen

printf("%10.2f", x)
(Thanks to Will Iverson for the update. He writes: “Note the lack of semi-colon. Improvement!”)

2012: Scala 2.10

Code: Alles auswählen

println(f"$x%10.2f")

gefunden hier: http://www.horstmann.com/