1

I have a long double and I want to print all digits of it (the complete number without scientific notation) using cout .

Here's the code :-

long double d = 3456489465498484.14159265358979;
cout << "Num: " <<  d << endl;

output:-

Num: 3.45649e+015

While I want the output to be

Num: 3456489465498484.14159265358979;

I tried precision and set precision but the dont seem to work this way. please help

UmeRonaldo
  • 619
  • 2
  • 7
  • 19
  • http://www.cplusplus.com/reference/ios/scientific/ and http://www.cplusplus.com/reference/iomanip/ should help. You can set the precision to show the decimal places. – Charles D Pantoga Jun 18 '13 at 18:21

1 Answers1

0

The internal representation of a floating-point value is typically binary, so initializing it requires converting from decimal to binary and displaying it requires converting from binary to decimal. Most decimal fractions do not have an exact binary representation, and most binary fractions do not have an exact decimal representation, so it is not meaningful, in general, to ask for "all" the digits. You've lost some digits on the way in, and will lose some more on the way out. Decide how many you want, and set the precision to match.

Pete Becker
  • 74,985
  • 8
  • 76
  • 165