Thema:
Re:C++ Frage flat
Autor: Sebu
Datum:21.10.21 21:24
Antwort auf:C++ Frage von publicmaw

>Ich will Strings in Doubles umwandeln, klappt aber nicht so richtig…
>
>Diese beiden Strings
>"656521508.266448"
>"656521508.433032"
>
>werden, wenn umgewandelt, beide zu 6.56522e+08
>
>Die Umwandlung habe ich per std::stold versucht, sowie per stringstream:
>
>stringstream s;
>double d;
>s<<str;
>s>>d;
>


Der double value wir schon richtig sein. Nur das ausgeben als string hat nicht genug digits.

So spuckt er die richtige Zahl aus.

#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
   double a = std::stod("656521508.266448");
   cout << std::setprecision(15) << a;

   return 0;
}

mehr dazu: [https://stackoverflow.com/questions/554063/how-do-i-print-a-double-value-with-full-precision-using-cout]


< antworten >