1. ## double/float data types

I just had a question about the double and float data types: what's the difference?

for example:
Code:
```double asdf = 1.123456789;
cout << asdf;```
would print out > 1.12346, which is only 6 digits, yet double is supposed to have 10 i thought?

if I were to declare the asdf var. as float, it would have printed the same thing. I thought double could hold more.

Thanks to anyone who can un-confuse me

2. AFAIK, the default precision is to 6 decimal places.

To get more, you could use the setprecision manipulator.

See URL here:
http://www.cplusplus.com/ref/iostrea...precision.html

3. I think that the exact size of the data types is machine dependent.If I did this correctly in the following code, you can see what the size of each variable is on your machine in bytes. each byte holds 4 bits so if it says that a float is 4. You can do 4 X 4 = 16 digits of precision.

Feel free to correct me if I am giving incorrect info.

Code:
```int _tmain(int argc, _TCHAR* argv[])
{
char c;
short s;
int i;
long l;
float f;
double d;
long double ld;
int array[ 20 ];
int *ptr = array;

cout << "sizeof c = " << sizeof c
<< "\tsizeof(char) = " << sizeof( char )
<< "\nsizeof s = " << sizeof s
<< "\tsizeof( short ) " << sizeof( short )
<< "\nsizeof i = " << sizeof i
<< "\tsizeof( int ) " << sizeof( int )
<< "\nsizeof l = " << sizeof l
<< "\tsizeof( long ) = " << sizeof( long )
<< "\nsizeof f = " << sizeof f
<< "\tsizeof( float ) = " << sizeof( float )
<< "\nsizeof d = " << sizeof d
<< "\tsizeof( double ) = " << sizeof( double )
<< "\nsizeof ld = " << sizeof ld
<< "\tsizeof( long double ) = " << sizeof( long double )
<< "\nsizeof array = " << sizeof array
<< "\nsizeof prt = " << sizeof ptr
<< endl;
return 0;
}```
Almost forgot. Then you can display the precesion of the digits by using the setprecesion() .

4. each byte holds 4 bits so if it says that a float is 4. You can do 4 X 4 = 16 digits of precision.

Feel free to correct me if I am giving incorrect info.
Each byte is four bits? What platform are you running? Each bytes is CHAR_BIT bits in size, and I'd be really really surprised if it was four.

Quzah.

5. >I think that the exact size of the data types is machine dependent.
Yes, but there are minimum requirements. For float that requirement is 6 and for double it's 10 IIRC. But the original question most likely used the default value of cout.precision(), which is 6 unless I'm mistaken.

>Each bytes is CHAR_BIT bits in size, and I'd be really really surprised if it was four.
I would be too. CHAR_BIT is required to be at least 8.

6. ## nice :)

very good example by big146 i must say

7. Also look at the members of numeric_limits<double>, declared in <limits>.