This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Difference between 0.9F  and 0.9 in float declaration Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Difference between 0.9F  and 0.9 in float declaration" Watch "Difference between 0.9F  and 0.9 in float declaration" New topic
Author

Difference between 0.9F and 0.9 in float declaration

Hardik Trivedi
Ranch Hand

Joined: Jan 30, 2010
Posts: 252
Hi all genius Javans out there..

I am a beginner in java...Please give me the difference between

Float a=new Float(0.5F);
and
Float a=new Float(0.5);
Rajeev Trikha
Ranch Hand

Joined: Jan 29, 2010
Posts: 85
The numeric literal 0.5 is actually a double which is downcasted, whereas 0.5F is explicitly a float.
For example you cannot say float f = 0.5; as 0.5 is double and cannot be assigned to a float.


Rajeev Trikha (SCJP 6)
Rajeev Trikha
Ranch Hand

Joined: Jan 29, 2010
Posts: 85
Incidentally I should have mentioned that the Float wrapper class has three constructors. It can accept float, double or string in the argument.

You can also say

Float f = new Float("4.5");
System.out.println(f+5);

and see 9.5 coming out in the output.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Difference between 0.9F and 0.9 in float declaration
 
Similar Threads
float problem
float variable
Passing string to wrapper classes
Kindly help me in Java.lang.float problems
Float.NaN