The March of Progress

Offtopic. Keine Bezug zur Programmierung, just Smalltalk.
Antworten
Benutzeravatar
Xin
nur zu Besuch hier
Beiträge: 8858
Registriert: Fr Jul 04, 2008 11:10 pm
Wohnort: /home/xin
Kontaktdaten:

The March of Progress

Beitrag von Xin » So Jan 29, 2017 9:53 pm

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/
Merke: Wer Ordnung hellt ist nicht zwangsläufig eine Leuchte.

Ich beantworte keine generellen Programmierfragen per PN oder Mail. Dafür ist das Forum da.

Antworten