我用这个:
int newWidth = Math.round(297 * (40 / 414));
在代码中,数字实际上是变量,但这些是他们持有的,当我运行时代码newWidth返回为0,我期待28或29.我没有看到这里有什么问题...
40 / 414被舍入到0立即,因为它只适用于整数.您必须将其中一个操作数强制转换为double/ float或double立即使用:
int newWidth = (int)Math.round(297 * (40.0 / 414));
要么:
int newWidth = (int)Math.round(297 * ((double)40 / 414));
| 归档时间: | 
 | 
| 查看次数: | 200 次 | 
| 最近记录: |