views:

76

answers:

3

How to convert a double into a floating-point string representation without scientific notation in C++. "Small" samples (effective numbers may be of any size, such as 1.5E200 or 1e-200) :

0.0000000000000000000000000000000000000000000000000000000023897356978234562

Thank you.

+2  A: 

It looks like you can do something like:

printf("%.999f", x);

With 1e-200, you get:

0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009999999999999999821002623990827595960544117892897470996150535982465624909474979367219721317562018041970215704550302992936249224948218323830116325579063735520859620984084769134554890828598863554536620439732820241331540672308512679754268595351951382901471352304920064954568524027925980061836920599672604679919133131325752127067572867114833324440862265532435494287445976335078589119159474703853650968495892746707328834776970293406573920527864300486054644847962408236227259004848949563992732691986020654439926147460937500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

You may choose to do further processing of the output (such as eliminating more digits of precision than you need).

Greg Hewgill
+7  A: 
string doubleToStr(double d)
{
    stringstream ss;
    ss << fixed << setprecision(400) << d;
    return ss.str();

}
Burgos
+1  A: 

I need to get a little graphic here, you are going to get hurt. Converting a floating point number to its decimal representation should only ever be done to help a human look at it. After a couple of days of eyeballing numbers formatted like that, this human is going to hunt you down and beat the living crap out of you.

Hans Passant