My code converts a long double number into a string. When it display the string, it shows in scientific format. How can I make the function shows the string in decimal format? Can I use setiosflag for the decimal formating? If I can use it, how?
#include <iostream>
#include <sstream>
#include <iomanip>
using namespace std;
string convertToString(long double MyValue)
{
ostringstream OutStream;
// try to use setiosflags but it doesn't work
cout<<setiosflags(ios::fixed)<<setiosflags(ios::showpoint)
<<setprecision(2);
OutStream << MyValue;
return (OutStream.str());
}
void main() {
long double input=456743332;
string output;
output=convertToString(input);
cout<<"output is "<<output<<endl;
}
much appreciated,
ethereal

New Topic/Question
Reply



MultiQuote



|