-4

Possible Duplicate:
double truncates at 7 characters of output

C++ why I retrieve double as this format

1.4547e+08

If i see the data itself, it should be

1.45470197.00

anyone got any idea how to convert that double 1.4547e+08 back to this 1.45470197.00

Community
  • 1
  • 1
  • 1
    The format you given 1.45470197.00 isn't valid, there are no numbers with more than one decimal point. Do you mean 145,470,197.00? – Mithrandir Aug 04 '12 at 19:38
  • 2
    FYI, that “format” is called [scientific notation](http://en.wikipedia.org/wiki/Scientific_notation). –  Aug 04 '12 at 19:39
  • 1
    Please consider *accepting* answers to previous questions. Do you really mean `1.45470197.00`, with *two* decimal points? – thb Aug 04 '12 at 19:40

1 Answers1

5

If you're printing data with std::cout, use std::fixed to prevent scientific notation

double d = 145470197.00;
std::cout << std::fixed << d;
Kent
  • 996
  • 6
  • 10
  • How do i use fixed for assigning the value to variable – Baoky A New Programer Aug 04 '12 at 19:45
  • 1
    @BaokyANewProgramer: You can't, unless you want to store it as a string, in which case, you lose your ability to do math on it. The double is not stored as 145470197.00, or as 1.4547e+08, it is stored as a series of bits in (most likely) [this format](http://en.wikipedia.org/wiki/IEEE_floating_point). The decimal number you see on screen is only how the ostream function chooses to interpret those bits. – Benjamin Lindley Aug 04 '12 at 19:55