Forums Register Login

Difference between 0.9F and 0.9 in float declaration

+Pie Number of slices to send: Send
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);
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
Remember to always leap before you look. But always take the time to smell the tiny ads:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 8375 times.
Similar Threads
Passing string to wrapper classes
Float.NaN
Kindly help me in Java.lang.float problems
float problem
float variable
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 04:24:02.