|
-
Aug 20th, 2006, 10:39 PM
#1
Thread Starter
PowerPoster
[RESOLVED] Data type float
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”
-
Aug 21st, 2006, 09:51 AM
#2
Re: Data type float
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.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Aug 21st, 2006, 10:10 PM
#3
Thread Starter
PowerPoster
Re: Data type float
 Originally Posted by CornedBee
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.
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.
-
Aug 22nd, 2006, 06:18 AM
#4
Re: Data type float
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"
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Aug 22nd, 2006, 07:02 AM
#5
Thread Starter
PowerPoster
Re: Data type float
 Originally Posted by ComputerJy
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"
Can you explain this statement further? I'm not clear what you are saying.
-
Aug 22nd, 2006, 07:21 AM
#6
Re: Data type float
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.
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Aug 23rd, 2006, 12:59 AM
#7
Thread Starter
PowerPoster
Re: Data type float
 Originally Posted by ComputerJy
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.
Thanks a lot, now I got the point.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|