Reputation: 313
I have a number_to_string function which converts numbers to string. Now I want to output the resulted string without scientific notation. Here's my code :
#include <iostream>
#include <sstream>
using namespace std;
string number_to_string( double value )
{
string result;
stringstream convert;
convert << value;
result = convert.str();
return result;
}
int main()
{
double d = 591284081248903124;
string s = number_to_string( d );
cout << s << endl; // why it shows 5.91284e+17 ?!?!
return 0;
}
Upvotes: 1
Views: 316
Reputation: 2274
Add convert << std::setiosflags (std::ios::fixed);
before line convert << value;
. And don't forget to #include <iomanip>
.
Upvotes: 2