Java: double vs float

后端 未结 6 1205
一整个雨季
一整个雨季 2020-12-09 16:37

In another Bruce Eckel exercise, the code I\'ve written takes a method and changes value in another class. Here is my code:

class Big {
  float b;
}

public         


        
6条回答
  •  无人及你
    2020-12-09 16:46

    Yes, but you have to specify that they are floats, otherwise they are treated as doubles:

    z.b = 2.2f
    

    The 'f' at the end of the number makes it a float instead of a double.

    Java won't automatically narrow a double to a float.

提交回复
热议问题