What does the suffix "f" mean in Java code?

Here is an explanatory code. The language is Java, and the code uses Android.

fg.setTextSize(height*0.50f); //<-'f' is in the brackets 

or

 @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); sWidth = w / 3f; // <-'f' is here } 

What does the suffix "f" mean?

+8
java
source share
5 answers

It indicates a literal float .

+13
source share

It indicates that 3 is float not integer; otherwise, 0.50 is float not double. As with any other Java program.

+5
source share

float;)

this is a 3, which is a float, not an int

+2
source share

This is a float, not a double. This is the basic Java (C) notation.

+2
source share

You do not need to add f if you enter 0 or 1 or during certain appointments. But in other cases, you need it especially when the compiler cannot determine whether its float or double or int or whether it needs to somehow pass a value. This is insanely contrary to reality.

+1
source share

Source: https://habr.com/ru/post/650931/


All Articles