尝试将厘米转换为英寸,然后四舍五入到最近的半英寸并打印1个小数点。
3.1 = 3.0
3.2 = 3.0
3.3 = 3.5
3.6 = 3.5
3.8 = 4.0
float index;
float height;
index = (Math.round((height * .393701)*2))/2;
text.setText("Index: " + index);
当我打印索引时,它不会显示小数。一旦数字达到.75或更高,它会四舍五入到下一个更高的整数。
发布于 2016-09-26 02:39:10
我在每个数字的末尾加上一个f。
(Math.round((height / 2.54f)*2f)/2f)
高度
147 / 2.54 = 57.874016 = 58
148 / 2.54 = 58.26772 = 58.5
发布于 2016-09-25 14:27:35
尝尝这个,
float index;
float height;
index = (float) (Math.round((height / 2.54) * 10) / 10.0);
text.setText("Index: " + index);
https://stackoverflow.com/questions/39683871
复制相似问题