作者热门文章
- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我正在做 float
s 和 int
s 的乘法和除法,我忘记了隐式转换规则(而且问题中的单词似乎太模糊,无法搜索更多比在这里问快)。
如果我有两个 int
,但我想做浮点除法,我只需要转换一个或两个操作数吗?乘法怎么样 - 如果我将 float
和 int
相乘,答案是 float
吗?
最佳答案
您不能将 float
除以 int
的结果分配给 int
,反之亦然。
所以答案是:
If I have two
int
s, but I want to do floating point division…?
一个 Actor 就足够了。
If I multiply a
float
and anint
, is the answer afloat
?
是的。
float f = 1000f;
int i = 3;
f = i; // Ok
i = f; // Error
f = i/f; //Ok 0.003
f = f/i; //Ok 333.3333(3)
i = i/f; //Error
i = f/i; //Error
关于java - float/int 隐式转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4097694/
我是一名优秀的程序员,十分优秀!