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.

29th Sep 2017, 12:29 PM
Gowtham Saravanan
Gowtham Saravanan - avatar
7 Antworten
+ 16
f tells the compiler that your variable type is float not a double. float x = 3.14f; double y = 3.14;
29th Sep 2017, 12:31 PM
Babak
Babak - avatar
+ 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++)
29th Sep 2017, 12:40 PM
Babak
Babak - avatar
+ 2
by default, Java will treat 1.1 as a double, not a float
29th Sep 2017, 12:32 PM
forrest
+ 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
29th Sep 2017, 12:36 PM
forrest
+ 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
29th Sep 2017, 12:47 PM
forrest
0
we have already said that keyword "float" at the beginning know?
29th Sep 2017, 12:32 PM
Gowtham Saravanan
Gowtham Saravanan - avatar
- 1
we have already said that is float in the begining right??
29th Sep 2017, 12:42 PM
Gowtham Saravanan
Gowtham Saravanan - avatar