java内部float,Java中的float是什么?
生活随笔
收集整理的這篇文章主要介紹了
java内部float,Java中的float是什么?
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
I wrote this code:
float b = 3.6;
and I get this:
Error:Unresolved compilation problem:
Type mismatch: cannot convert from double to float
Why? Whats the definition of float?
解決方案
In Java, when you type a decimal number as 3.6, its interpreted as a double. double is a 64-bit precision IEEE 754 floating point, while floatis a 32-bit precision IEEE 754 floating point. As a float is less precise than a double, the conversion cannot be performed implicitly.
If you want to create a float, you should end your number with f (i.e.: 3.6f).
總結
以上是生活随笔為你收集整理的java内部float,Java中的float是什么?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python读取路径太长_路径名太长,无
- 下一篇: 24点游戏java_Java实现24点小