Click to See Complete Forum and Search --> : Compiler Error


mikeshn
06-04-2002, 04:02 PM
I declare variable as float point and got the compiler error

float f = 3.14;

Why it happened?

Thanks

bwkaz
06-04-2002, 04:25 PM
That doesn't sound like a compiler error...

What command did you use to compile, and what's the full output of that command?

mikeshn
06-04-2002, 04:34 PM
That's errot message I got from JAVA

Bitwise.java:3: possible loss of precision
found : double
required: float
float f = 3.14;
^
1 error

Energon
06-04-2002, 11:37 PM
I think the reason is that by default floating point values are double in Java. So what I think you want is this:

float f = 3.14f;

to say "yes, I want this number to be a float instead of a double". I know it's that way in C, so it might be your answer in Java.

bwkaz
06-07-2002, 01:56 PM
Yeah, if that doesn't work, try this

float f = (float)3.14;

But I'm pretty sure Java handles it right when you append an f.