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

后端 未结 9 2198
难免孤独
难免孤独 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:25

    You need to put the 'f' at the end, otherwise Java will assume its a double.

    0 讨论(0)
  • 2020-12-09 19:26

    The default Java type which Java will be using for a float variable will be double. So, even if you declare any variable as float, what compiler has to actually do is to assign a double value to a float variable, which is not possible.So, to tell compiler to treat this value as a float, that 'f' is used.

    0 讨论(0)
  • 2020-12-09 19:29

    If f is not precised at the end, value is considered to be a double. And a double leads to more bytes in memory than float.

    0 讨论(0)
提交回复
热议问题