Neuling..., rechnen mit kommastellen
-
Hi...
hoffe ich bin hier richtigalso folgendes versuche mich in c/c++
nutze Dev-C++ ver. 4.990
egal ob ich float, double oder long double benutze, es ist immer das selbe ergebnis
1.57143 ich nehme an das ist standard float oder...?
mit dem windows taschenrechner ist das ergebnis 1.57142857142867...und noch ein paar kommastellenhab mir gedacht die konsole gibt eventuell nur float werte aus, aber auch wenn ich die werte in eine datei schreiben lasse... ist es das selbe.
was kann ich an dem programm ändern um genauer rechnen zu können?
long double, so wie ich das verstehe müsste doch auf 19 ? stellen genau rechnen können?thx im voraus, Andi
#include <iostream> #include <fstream> #include <stdio.h> #include <stdlib.h> using namespace std; int ao,bo,co; float a,b,c; double aa,bb,cc; long double aaa,bbb,ccc; int main () { ao=33; bo=21; co=ao/bo; a=0.33f; b=0.21f; c=a/b; aa=0.33; bb=0.21; cc=aa/bb; aaa=0.33l; bbb=0.21l; ccc=aaa/bbb; cout<< " int : " << co << endl; cout<< " float : " << c << endl; cout<< " double : " << cc << endl; cout<< " long double : " << ccc << endl; system ("pause"); }
-
#include <iostream> #include <fstream> #include <stdio.h> #include <stdlib.h> using namespace std; int ao,bo,co; float a,b,c; double aa,bb,cc; long double aaa,bbb,ccc; int main () { ao=33; bo=21; co=ao/bo; a=0.33f; b=0.21f; c=a/b; aa=0.33; bb=0.21; cc=aa/bb; aaa=0.33l; bbb=0.21l; ccc=aaa/bbb; cout<< " int : " << std::setprecision(20) <<co << endl; cout<< " float : " << std::setprecision(20) << c << endl; cout<< " double : " << std::setprecision(20) << cc << endl; cout<< " long double : " << std::setprecision(20) << ccc << endl; system ("pause"); }
Das sollte helfen.