# I don't understand what the difference is between a float and a double

• 11-03-2012, 07:45 AM
psx2514
I don't understand what the difference is between a float and a double
Whenever I look this up, the explanation I get seems to be convoluted to me, and I can't get a simple straight answer. So, to be more specific, could someone explain to me, for example what the difference between double a = 2.25 and float a = 2.25f is? Also, when is it more appropriate to use a float over a double, and vice versa (I'm looking for specific examples if possible)?

Also, I don't know if this is related to this question or not, but how do you get a program to NOT truncate a zero at the end of a decimal. For example, I want to program to output 0.50 instead of 0.5
• 11-03-2012, 08:29 AM
killutch
Re: I don't understand what the difference is between a float and a double
double can hold more numbers

float = 32-bit
double = 64-bit

with primitives you are limited in how much can be held because it reserves the space on the machine and doesn't change.
• 11-03-2012, 10:44 AM
psx2514
Re: I don't understand what the difference is between a float and a double
Quote:

Originally Posted by killutch
double can hold more numbers

float = 32-bit
double = 64-bit

with primitives you are limited in how much can be held because it reserves the space on the machine and doesn't change.

I know that, but that doesn't really answer my question.
• 11-03-2012, 11:03 AM
noctarius
Re: I don't understand what the difference is between a float and a double
• 11-03-2012, 11:18 AM
DarrylBurke
Re: I don't understand what the difference is between a float and a double
A double can for some values hold a more accurate representation than a float.

To understand all about this in more detail, read What Every Computer Scientist Should Know About Floating-Point Arithmetic

db
• 11-03-2012, 11:44 AM
psx2514
Re: I don't understand what the difference is between a float and a double
Quote:

Originally Posted by psx2514
So, to be more specific, could someone explain to me, for example, what the difference between double a = 2.25 and float a = 2.25f is? Also, when is it more appropriate to use a float over a double, and vice versa (I'm looking for specific examples if possible)?