Reputation: 521
I'm writing a class in C++ that needs some constants that are accessible throughout the whole class. Normally I would use a #define, a const- or a static declaration but there is something strange happening: So for example I write
#define Rm 8.3144621
but std::cout << Rm << std::endl;
prints 8.31446.
I also tried
#define Rm 831.44621e-2
and const double Rm = 8.3144621
and static double Rm = 8.3144621
and every possible way to initialize or cast to a double constant.
Is there a solution for that or do I have to use fields?
Upvotes: 2
Views: 126
Reputation: 23644
If you need to output the double with all digits, you need to set correct precision:
std::cout << std::fixed;
std::cout << std::setprecision(7) << Rm << std::endl;
See a live demo here: Double print Demo
Upvotes: 6