aspose file tools
The moose likes Beginning Java and the fly likes Float and Double Data Type Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Float and Double Data Type" Watch "Float and Double Data Type" New topic
Author

Float and Double Data Type

Jessica Lang
Ranch Hand

Joined: Jul 23, 2002
Posts: 61
Hello,
float scores[] = (76.0, 84.5, 92.5, 88.0, 96);
Compilation error:
possible loss of precision
found: double
required: float
Why the float type is insufficient for the storage of one decimal point value? The above statements compiled with no error if double type is used.
Thanks....
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Don't forget the constants initializing the array are double precision numbers. If you want to initialize the float array (that is single precision), you must write the constants as 76.0F, 84.5F, 92.5F, 88.0F, 96.0F.
[ May 15, 2003: Message edited by: Barry Gaunt ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Jessica Lang
Ranch Hand

Joined: Jul 23, 2002
Posts: 61
Oh yeah, I just remembered that! I think I read it somewhere....Thanks again.....
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Float and Double Data Type
 
Similar Threads
valid assignment
Double and Float size
overloading v/s inheritance
Automatic type promotion
JSF - "Can't set property..."