Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
Mein Wert ist aber jetzt jedes mal 808.f / 10.f gewesen. Das hat 9 mal geklappt und beim 10 mal liefert es einen falschen Wert.
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 |
float hp_data = 919.20001f std::string foo; std::ostringstream ss; ss << hp_data; foo = ss.str(); |
C-/C++-Quelltext |
|
1 2 3 4 5 |
int a = 213; int b = a % 10; // ergibt 3 int c = a / 10 % 10; // ergibt 1 int d = a / 100 % 10; // ergibt 2 |
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »Shorkan« (26.07.2015, 17:26)
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
float hp_data = 919.2341f std::string foo; std::ostringstream ss; int num = 1; float temp_data = hp_data; if ( temp_data >= 1 ) { while ( temp_data >= 1 ) { temp_data /= 10.f; num += 1; } } else { num += 1; } ss << std::set_precision(num) << hp_data; foo = ss.str(); |
C-/C++-Quelltext |
|
1 |
std::cout << std::fixed << std::setprecision(2) << 123.4567f; |
Werbeanzeige