I wrote this code:
float b = 3.6;
and I get this:
Error:Unresolved compilation problem:
Type mismatch: cannot convert from double to float
Why? Whats the definition of float?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In Java, when you type a decimal number as
3.6, its interpreted as adouble.doubleis a 64-bit precision IEEE 754 floating point, whilefloatis a 32-bit precision IEEE 754 floating point. As afloatis less precise than adouble, the conversion cannot be performed implicitly.If you want to create a float, you should end your number with
f(i.e.:3.6f).For more explanation, see the primitive data types definition of the Java tutorial.