File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP 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