后缀'f'在Java代码中的含义是什么?

san*_*one 8 java

这是解释性代码.语言是Java,代码使用Android.

fg.setTextSize(height*0.50f); //<-'f' is in the brackets
Run Code Online (Sandbox Code Playgroud)

要么

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

后缀'f'是什么意思?

Phi*_*unt 13

它表示float文字.

  • 从w/3f中删除f将导致整数除法,而不是浮点除法,因为3是int而3f是浮点数.3f和((float)3)将计算为相同的值,但是(float)3可以在运行时转换,而3f总是在编译时计算. (3认同)
  • @askmo,同样适用于.net.EG如果要声明十进制文字,可以将其写为`5m`,或者查看http://msdn.microsoft.com/en-us/library/b1e65aza(v=VS.100)中的float示例的.aspx (2认同)

Tas*_*han 5

它表示3是浮点数不是整数,在其他情况下0.50浮点数不是双精度.就像在任何其他java程序中一样.