Good day

A simple question, whats the difference between :

andCode:

float number = 12.34f;

Code:

float number = 12.34;

Printable View

- 12-28-2002laasundefloat
Good day

A simple question, whats the difference between :

Code:

float number = 12.34f;

Code:

float number = 12.34;

- 12-28-2002Prelude
>float number = 12.34f;

This assigns a single precision value to a single precision variable.

>float number = 12.34;

This assigns a double precision value to a single precision variable, your compiler may warn about this.

-Prelude - 12-28-2002elad
that then begs the question, What's the difference between a single precision variable and a double precision variable?

- 12-28-2002Crimpy
A double precision variable has twice the precision of a single precision variable. Isn't that kind of obvious?

- 12-28-2002Polymorphic OOP
Actually, double

*doesn't*necissarily mean twice the precission. - 12-28-2002Crimpy
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.

- 12-29-2002vasanth
consider a number 3.14285

If you store it in a variable do you want to save it as 3.14 or 3.142. - 12-30-2002laasunde
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;`

Code:`float number = 12.34f;`

- 12-30-2002Polymorphic OOPQuote:

*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;`

Code:`float number = 12.34f;`

- 12-30-2002laasundeQuote:

*Originally posted by Polymorphic OOP*

**No, the former has more precision than the latter.**

float number = 12.34; // 14 digits precision

float number = 12.34f; // 7 digits precision

Both using 4 bytes of memory. - 12-30-2002Polymorphic OOP
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.