1. ## float

Good day

A simple question, whats the difference between :

Code:
`float number = 12.34f;`
and

Code:
`float number = 12.34;`

2. >float number = 12.34f;
This assigns a single precision value to a single precision variable.

>float number = 12.34;

-Prelude

3. that then begs the question, What's the difference between a single precision variable and a double precision variable?

4. A double precision variable has twice the precision of a single precision variable. Isn't that kind of obvious?

5. Actually, double doesn't necissarily mean twice the precission.

6. Yea, but you can't quantify exactly what the difference is, so twice as much as as good as any for a "Duh" question like that.

7. consider a number 3.14285

If you store it in a variable do you want to save it as 3.14 or 3.142.

8. According to my c++ book float uses 7 digits precision and a total of 4 bytes. Does that mean if I write
Code:
`float number = 12.34;`
it uses 7 digits precision and if I write
Code:
`float number = 12.34f;`
it uses 14 digits precision ?

9. Originally posted by laasunde
According to my c++ book float uses 7 digits precision and a total of 4 bytes. Does that mean if I write
Code:
`float number = 12.34;`
it uses 7 digits precision and if I write
Code:
`float number = 12.34f;`
it uses 14 digits precision ?
No, the former has more precision than the latter.

10. Originally posted by Polymorphic OOP
No, the former has more precision than the latter.
So this is correct then

float number = 12.34; // 14 digits precision

float number = 12.34f; // 7 digits precision

Both using 4 bytes of memory.

11. Nono, float is usually 4 bytes and double is usually 8 bytes. Notice it's usually -- the standard only says that double has to be greater than or equal to the size and precission of float.

4-byte float is generally accurate to 23 binary digits and 8-byte double is generally accurate to 52 binary digits.