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?
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
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
sscanf( ).
Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah
You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie
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; }
Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah
You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie
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;
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
Thanks Hammer, didn't know about the precision() function.