sandalone
sandalone

Reputation: 41759

What does suffix 'f' mean in Java code?

Here's the 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?

Upvotes: 8

Views: 7555

Answers (5)

locka
locka

Reputation: 6029

You don't need to append the f if entering 0 or 1 or during certain assignments. But other times you do need it especially when the compiler can't tell if its a float or a double or an int or needs to cast the value in some way. It's maddeningly inconsistent really.

Upvotes: 1

Tasawer Khan
Tasawer Khan

Reputation: 6148

It indicates 3 is float not integer in other case 0.50 is float not double. Just like in any other java program.

Upvotes: 5

Pontus Gagge
Pontus Gagge

Reputation: 17268

It's a float, not a double. This is basic Java (C) notation.

Upvotes: 2

Nanne
Nanne

Reputation: 64409

float ;)

it's a 3 that is a float, not an int

Upvotes: 2

Phil Hunt
Phil Hunt

Reputation: 8541

It indicates a float literal.

Upvotes: 13

Related Questions