Click here to Skip to main content
15,884,537 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I am new to java. My question is when I try to do following:

float a = 10.1;

I get error stating that required was float and this is double.
Posted

1 solution

In case of Java, when you define a decimal number as 10.1, its interpreted as a double. double is a 64-bit precision floating point, while float is a 32-bit precision floating point. As float is less precise than a double, the conversion cannot be performed implicitly.

If you want to create a float number, you should end your number with f (i.e.: 10.1f).
Fore more information visit here..
http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900