Why is the letter f used at the end of a float no.?

后端 未结 9 2271
难免孤独
难免孤独 2020-12-09 18:52

I just wanted some information about this.

float n = 2.99944323200023f

What does the f at the end of the literal do? What is i

9条回答
  •  情深已故
    2020-12-09 19:10

    When you write 1.0, it's ambiguous as to whether you intend the literal to be a float or double. By writing 1.0f, you're telling Java that you intend the literal to be a float, while using 1.0d specifies that it should be a double (which is also default if you do not specify that explicitely).

提交回复
热议问题