0
In java ,float a =1.1f; what is this f stands for??
In java, when a value is assigned to a float. like float a = 1.1f; why we are putting the f at the last of the assigned value.
7 Answers
+ 16
f tells the compiler that your variable type is float not a double.
float x = 3.14f;
double y = 3.14;
+ 13
If you ignore that f, compiler does an implicit conversion between types. (that is not a good practice in programming- at least in C++)
+ 2
by default, Java will treat 1.1 as a double, not a float
+ 2
Java won't implicitly cast to a float because double has higher precision. you could also write
float f = (float) 3.14
but it won't work if you don't explicitly tell it to do so
+ 1
you're declaring the variable to be of type 'float', but not doing anything to the value itself. Java will treat it as a double by default, and this can least to unexpected errors
0
we have already said that keyword "float" at the beginning know?
- 1
we have already said that is float in the begining right??