What does suffix 'f' mean in Java code?

匿名 (未验证) 提交于 2019-12-03 08:33:39

问题:

Here's the explanatory code. The language is Java and the code uses Android.

fg.setTextSize(height*0.50f); //

or

@Override protected void onSizeChanged(int w, int h, int oldw, int oldh) {     super.onSizeChanged(w, h, oldw, oldh);     sWidth = w / 3f; // 

What does the suffix 'f' mean?

回答1:

It indicates a float literal.



回答2:

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



回答3:

float ;)

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



回答4:

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



回答5:

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.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!