Hi..
Can you explain what the difference between two lines stated below is?
float a = 10.125;
float b = 10.125F;
Actually what I want to know is the usefulness of âFâ
Printable View
Hi..
Can you explain what the difference between two lines stated below is?
float a = 10.125;
float b = 10.125F;
Actually what I want to know is the usefulness of âFâ
The first is a double literal, the second a float literal. With the F postfix, the compiler can warn you about lost precision in the literal, and it will help for overload resolution in functions overloaded for float and double.
Quote:
Originally Posted by CornedBee
Thanks for your comment,
If I used the following line in an application it will gives complie error.
float a = 10.125;
Can you explain it, please.
Because the double is 64-Bit var, but the float is 32-bit, that's why you are getting this error: you are using 64bit value inside a 32bit variable.
If you use the postfix "F" it will go away, because the java compiler will understand that the value is of type "float"
Quote:
Originally Posted by ComputerJy
Can you explain this statement further? I'm not clear what you are saying.
any value that has a floating point is a double in java.
The double is a 64bit value (8-bytes) but you are attempting to put the double value in a float variable, which can hold only 32bit value (4-bytes just like the integer), java now thinks you are attempting to put 8bytes inside a 4byte container and that's not possible, right?
So if you use the literal "F" as a postfix of the value, Java will understand this is a float value not a double value, so now it knows the value will fit in the container.
Quote:
Originally Posted by ComputerJy
Thanks a lot, now I got the point.