Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

C# - Variablen Formatierung

Empfohlene Antworten

Veröffentlicht

Morgen

Also ich muss von der Schule her ein Programm schreiben. Das klappt auch wunderbar nur die Formatierung der Ausgabe will nicht so ganz...

Also z.B. Normale Ausgabe = 5

Gewünschte Ausgabe = 5,00

Ich weiß, dass das über {0:00} geht nur hab ich kA wo ich das Einsetzen muss

Hier mal der Quelltext:

Console.WriteLine("\tDer Benzinverbrauch auf 100 km betrug " + verbrauch + " Liter");

verbrauch ist die Variable die Formatiert werden sollte.

Danke schonmal

  • Autor

Danke genau das wars!

Nur hab ich jetzt noch folgendes Problem bei einer anderen Aufgabe.

Und zwar:

Console.WriteLine("\t\t  2              "+ zinsen + "               "+ kapitaluzins);
So funktioniert es schonmal nicht:
Console.WriteLine("\t\t  2              {0:0.00}", zinsen + "               {0:0.00}", kapitaluzins);

Die Zinsen und das neue Kapital+Zins müssen in einer Zeile stehen.

Du hast 2 Möglichkeiten:


int zahl1 = 2;

int zahl2 = 4;

Möglichkeit 1:

Console.WriteLine("BLABLABLA" + zahl1.toString("D2") + "BLA" +zahl2.toString("D2");

Möglichkeit 2:

Console.WriteLine("BLABLA {0:00} BLA BLA BLA {1:00} BLA BLA BLA", zahl1, zahl2);


in den Klammer gibts du einen Platzhalter an, der seine Variablen am Ende des Strings durch ein Komma getrennt findet.

  • Autor

Möglichkeit 2 war Perfekt Danke schöööön :)

Letzte frage: Wie richte ich Zahlen am Komma aus?

Also, dass das komma immer auf der selben stelle ist egal wie lang die Zahl ist

Bearbeitet von Jehzus

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.