[英]Java Decimal issue with format #.# in android
I have used this following code to get the decimal format and set it to edit text. 我使用以下代码来获取十进制格式并将其设置为编辑文本。
DecimalFormat decimalFormat = new DecimalFormat("#.#");
editSoilDepth.setText(decimalFormat.format(5.58f));
If I do so it will give me out put as: 5.9 but i do not want to replace the decimal first value and want to print as 5.5 如果我这样做它会给我输出为: 5.9但我不想替换小数第一个值,并希望打印为5.5
How can i do so? 我怎么能这样做?
Any suggestion will be appreciated. 任何建议将不胜感激。
在使用DecimalFormat
之前添加此行:
df.setRoundingMode(RoundingMode.DOWN);
DecimalFormat decimalFormat = new DecimalFormat("#.#");
decimalFormat.setRoundingMode(RoundingMode.DOWN);
decimalFormat.format(5.58f);
试试这个吧
double roundOff = Math.round(a * 10.0) / 10.0;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.