Results 1 to 8 of 8
 11032012, 06:45 AM #1Member
 Join Date
 Oct 2012
 Posts
 50
 Rep Power
 0
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
 11032012, 07:29 AM #2Member
 Join Date
 Sep 2012
 Posts
 70
 Rep Power
 0
Re: I don't understand what the difference is between a float and a double
double can hold more numbers
float = 32bit
double = 64bit
with primitives you are limited in how much can be held because it reserves the space on the machine and doesn't change.
 11032012, 09:44 AM #3Member
 Join Date
 Oct 2012
 Posts
 50
 Rep Power
 0
 11032012, 10:03 AM #4Member
 Join Date
 Jun 2012
 Location
 Remscheid, Germany
 Posts
 63
 Rep Power
 0
Re: I don't understand what the difference is between a float and a double
32bit = single precision
64bit = double precision
Primitive Data Types (The Java™ Tutorials > Learning the Java Language > Language Basics)
 11032012, 10:18 AM #5
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 FloatingPoint Arithmetic
dbIf you're forever cleaning cobwebs, it's time to get rid of the spiders.
 11032012, 10:44 AM #6Member
 Join Date
 Oct 2012
 Posts
 50
 Rep Power
 0
 11032012, 03:30 PM #7Member
 Join Date
 Jun 2012
 Location
 Remscheid, Germany
 Posts
 63
 Rep Power
 0
Re: I don't understand what the difference is between a float and a double
Please read the answers again.
 11042012, 07:29 PM #8Member
 Join Date
 Sep 2012
 Posts
 70
 Rep Power
 0
Re: I don't understand what the difference is between a float and a double
double a = 2.25 and float a = 2.25f
in this example the value is the same. There is no difference accept the double takes up more space on the machine and each might have to be handled a little differently depending on the situation with type casting and what not.
Similar Threads

What is the difference between float and double?
By Nosrettap in forum New To JavaReplies: 5Last Post: 09232014, 12:20 PM 
double and float value in java
By arvindmer in forum New To JavaReplies: 6Last Post: 05282009, 04:51 PM 
Float vs. Double
By javanub in forum New To JavaReplies: 1Last Post: 11232008, 12:11 PM 
Float and double to binary
By rosh72851 in forum Advanced JavaReplies: 3Last Post: 09242008, 06:29 AM 
Put float value to double
By chamalsl in forum New To JavaReplies: 3Last Post: 09202008, 04:52 AM
Bookmarks