DecimalFormat 未正确格式化我的数字
我想将所有数字四舍五入到小数点后一位。
例如
22.0
-6.1
我正在使用:
DecimalFormat decimalFormat = new DecimalFormat("0.0");
middlePanelTextView.setText(decimalFormat.format(score.getElevationAngle()));
但整数后面没有附加 0。
-18 should be -18.0 etc.
相反,我的值显示为 -18。
I want to round all of my numbers to 1 decimal place.
For example
22.0
-6.1
I am using:
DecimalFormat decimalFormat = new DecimalFormat("0.0");
middlePanelTextView.setText(decimalFormat.format(score.getElevationAngle()));
But whole numbers don't have a 0 appended to it.
-18 should be -18.0 etc.
instead my value shows up as -18.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
.@ 代表有效数字 0 则不然。
.# 代表可选数字所以尝试“##@.@”
http:// developer.android.com/reference/java/text/DecimalFormat.html
我不确定语法:但上面的文章应该为您提供所需的一切。
.@ represents a significant digit 0 doesn't.
.# represents and optional digit So try "##@.@"
http://developer.android.com/reference/java/text/DecimalFormat.html
I'm not sure about the syntax: but the above article should give you all you need.
尝试
Try
我的 TextView 正在切断数字。我的错。缩小字体大小。
My TextView was cutting off the digits. My fault. Shrank font size.
尝试使用
作为构造函数参数。
Try using
as the constructor parameter instead.
尝试使用以下代码:
Try using the following code: