Reputation: 83
I'm still a novice at C++ and have looked around on here for answers to my questions, but all answers seem a bit too technical and confuse me even more. Let me first state that I know, from the C++ tut I'm using that float = 4 bytes with approx. 7 digits. Double =8 bytes with approx. 15 digits. And Long double=8 bytes with approx 15 digits.
Here is my problem: I create a simple sum and declare variables using float, double and long double. But my answer on the console after building and running does not show the correct amount of digits. For float it is working fine, but not for the other two. Example:
float sum;
sum = 9.123456 * 5;
Now when I build and run that, the answer on the console shows 1.82469
for float(which is fine since it is 7 digits including the "dot"). But for both double and long double it still shows 1.82469
(7 digits) in my console when I run it.
So I have two questions:
Upvotes: 1
Views: 309
Reputation: 1680
1) cout << setprecision(15)
2) C++ standard not specifies types fully. For example, "long" can be 32 or 64 bit. So, "long double" can be equal to "double" and may be not.
Upvotes: 1