Results 1 to 3 of 3
- 11-15-2007, 05:28 PM #1
Senior Member
- Join Date
- Nov 2007
- Posts
- 111
- Rep Power
- 0
type mismatch: cannot convert from double to float
I have following line of code:
It gives me following errorJava Code:float average = 12.2;
I tried few things and was able to fix it using:Java Code:Type mismatch: cannot convert from double to float
I don't know why f is required with float value. Please explain.Java Code:float average = 12.2f;
- 11-15-2007, 10:18 PM #2
The default in java is that a primitive with a decimal in it is a double. For the lower precision float type we need to specify with a trailing "F", "f" or cast the value to float.
Same applies with int and long types using "L", "l" or long cast.
See paragraph 3 under the Literals header on Primitive Data Types.
- 11-16-2007, 01:24 PM #3
Senior Member
- Join Date
- Nov 2007
- Posts
- 111
- Rep Power
- 0
Similar Threads
-
How do I convert a decimal value to hexadecimal with double precision (64 bit)
By SKaur in forum New To JavaReplies: 7Last Post: 01-12-2008, 09:02 PM -
convert string to a double?
By javaMike in forum Advanced JavaReplies: 2Last Post: 11-27-2007, 03:10 AM -
convert string to float
By miss_dot in forum NetBeansReplies: 1Last Post: 11-14-2007, 11:26 PM -
Help with convert a double type number
By trill in forum New To JavaReplies: 1Last Post: 08-06-2007, 08:48 AM -
Error with convert to Float
By cachi in forum New To JavaReplies: 1Last Post: 08-06-2007, 02:18 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks