Float can hold 6 significant digits and double 10 (this is how the book tells me).

Consider this code i wrote to test :

``````int main()
{
double a=355979.567; //9 significant digits i think
cout<<a;
return 0;

}``````

The o/p is 3555980. i thought since 'a' is double it should show me what i assigned(355979.567).

in fact the o/p is same for float and long double as well?

Any1 can explain this?

how do float double and long double really differ other than their sizes ?

Edited by Kakashi Hatake: n/a

4
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by mike_2000_17

Here is a thread that talks about the floating point types here. And if you want the decimals to show you can use the <iomanip> header `cout << setprecision(5) << fixed;` You can check out this to get more manipulators and see what the ones I posted do.

I agree with sfuo, this is a matter of output formatting, not of the actual precision of the stored floating-point value. By default, the output format is somewhat automatic in the sense that if you have a number that is reasonably close to 0, it will be outputted in normal format (not scientific) and with some default number of digits (probably 5 or 6, from what you posted). Just set the precision to a really high number (like 25 or something) and you should see a difference between the float, double, and long double.

``cout << setprecision(5) << fixed;``

error: 'setprecision' was not declared in this scope

What header should i inlcude to use that ?