exponentielle Zahlen
-
Hi, ich habe folgenes Programm geschrieben:
#include <iostream>
#include <math.h>
using namespace std;int main()
{
double a;a = (pow(2,64)-1);
cout<<a;
cin.get();
return 0;
}jetzt hab ich das Problem, das ich "a" nicht also exponentielle Zahl (1.8*10^19) darstellen möchte sondern eher z.B. so: 1826400000000000000000000000 xD also schon mal thx für die hilfe.
PS:bin ein anfänger^^ also bitte einfach^^
pps: wie könnte ich das % zeichen (also für rest) auf double zahlen anwenden wenn ich weiss das sie ganzzahlig sind.
-
Bitte cpp- Tags benutzen. Und in C++ cmath, anstatt math.h benutzen.
#include <iomanip> ... cout<< fixed << a;
-
Moin,
du kannst die Ausgabe über flags steuern, konkret sieht das dann so aus:
#include <iostream> #include <math.h> using namespace std; int main() { double a; a = (pow(2,64)-1); cout.setf(ios:: fixed); //Gleitkommaformat cout<<a<< endl; cout.setf(ios:: scientific); //Exponentialformat cout<< a; cin.get(); return 0; }
-
Nebukat schrieb:
Moin,
du kannst die Ausgabe über flags steuern, konkret sieht das dann so aus:Es gibt einen Grund, warum es Standarmanipulatoren gibt.
-
Das mit iomanip kannt ich noch gar nicht
-
Bezüglich dem Modulo auf ganzahlige Zahlen, die in doubles gespeichert sind:
Du kannst deinen double nach int casten und ihn dann wie einen int behandelndouble a=5; int b=int(a)%3;
-
ne geht auch eifnacher mit einer funktion bzw mehreren
#include <cmath> double modf(long double x, long double *intpart); long double modf(long double x, long double *intpart); float modf(float x, float *intpart);