关闭。这个问题需要debugging details .它目前不接受答案。
想改进这个问题?将问题更新为 on-topic对于堆栈溢出。
4年前关闭。
Improve this question
我在浮点数据类型中采用 r=7.5。它显示以下错误
enter image description here
任何人都可以帮助我为什么它显示错误?
最佳答案
在 JLS 3.10.2
,定义浮点字面量形式:
A floating-point literal is of type float if it is suffixed with an ASCII
letter F or f;otherwise its type is double and it can optionally be suffixed
with an ASCII letter D or d (§4.2.3).
所以
float r=7.5
不正确,因为 7.5
是 double 型,不赋值给浮点型r
.您可以将其更改为float r=7.5f' or 'double r=7.5
关于java - 从 double 到 float 错误的可能有损转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44448571/