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.

Empfohlene Antworten

Veröffentlicht

Hi

Wie bekomme ich es bei C++ hin, dass bei der Ausgabe (console über cout) auf 2 Stellen hinterm Komma gerundet wird? :rolleyes: Hab das schon ewig nicht mehr gemacht und bekomms einfach nicht mehr hin... aber ich weiss, dass das irgendwie ging... :rolleyes:

precision gibt ja nur die gesamtlänge an und das bringt mir nichts. :( Und fixed hilft mir da auch nicht, ebensowenig wie width... :rolleyes:

double dZahl = 2.236;

cout << setprecision (2) << dZahl << endl;

und #include <iomanip> nicht vergessen! :bimei

  • Autor
Originally posted by vinc

double dZahl = 2.236;

cout << setprecision (2) << dZahl << endl;

So alleine funktionierte das aber nicht. Da gab er mir dann nur die Zahl mit e aus, da er insgesamt nur 2 Stellen dann nahm... Aber habs dann doch irgendwie hinbekommen auf der Arbeit. Ich poste es dann morgen mal eben hier erin, wie... ;)

Thx2all

tja, hab da auch noch was vergessen :rolleyes:

double dZahl = 2.236;

cout << setiosflags (ios::fixed) << setprecision (2) << dZahl << endl;

Hallo!

Falls du MS VC++ benutzt (Mit dem Borland Builder kenn i mich ned aus!)

kannst du ein Projekt mit MFC-Unterstützung erstellen! Da wäre nämlich bei CString eine Memberfunktion Format() mit der man ähnlich wie mit printf formatieren kann!(ohne Ausgabe halt!)

Bsp.:

CString hilfe;

double zahl=3.14;

hilfe.Format("Das ist eine Kommazahl: %.2lf ", zahl); //nun ist der obrige text in hilfe drin!

//Ausgabe mit cout:

cout << LPCTSTR(hilfe) << endl;

//LPCTSTR musst du verwenden da cout Schwierigkeiten mit CStrings hat!

falls du auf die MFC - Unterstützung verzichten willst, würd ich auch printf bevorzugen!

Ich hoffe dass dir das weitergeholfen hat!

Gruß

Azrael

double dblZahl = 2.34493;

cout << (double)(((long)(dblZahl * 100 + .49))) / 100;

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

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.