How do I properly convert huge numbers with decimal points
(ex. 14432454554.04524354) in string to double. I tried the function atof() but it has it's limits. Are there any other way?
Printable View
How do I properly convert huge numbers with decimal points
(ex. 14432454554.04524354) in string to double. I tried the function atof() but it has it's limits. Are there any other way?
For C way: http://www.rt.com/man/strtod.3.html
For a C++ way, try adapting this
sscanf( ).
strtod() function looks like it got all the numbers in the double, but
it change the number with an exponential notation.
I'm doing a calculator program and I need to keep everything in order. How the heck am I suppose to output the right answer with the decimal period in the right place.Code:#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
char a[] = {"123423423.34343"};
char *b;
double d;
d = strtod(a, &b);
cout << d << endl;
system("PAUSE");
return 0;
}
//the result:
1.23423e+08
Press any key to continue . . .
Code:#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
char a[] = {"123423423.34343"};
double d;
sscanf( a, "%lf", &d );
cout << d << endl;
system("PAUSE");
return 0;
}
I got the same result from your example XSquared.
I want this: 123423423.34343 on the output.
not 1.23423e+08
cout.precision( 20 );
cout << d << endl;
Thanks Hammer, didn't know about the precision() function.