Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/181.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 十进制格式无法正确格式化我的数字_Java_Android_Math_Decimalformat - Fatal编程技术网

Java 十进制格式无法正确格式化我的数字

Java 十进制格式无法正确格式化我的数字,java,android,math,decimalformat,Java,Android,Math,Decimalformat,我想把我所有的数字四舍五入到小数点后1位 比如说 22.0 -6.1 我正在使用: DecimalFormat decimalFormat = new DecimalFormat("0.0"); middlePanelTextView.setText(decimalFormat.format(score.getElevationAngle())); 但是整数没有附加0 -18 should be -18.0 etc. 相反,我的值显示为-18。尝试使用 DecimalFormat deci

我想把我所有的数字四舍五入到小数点后1位

比如说

22.0
-6.1
我正在使用:

DecimalFormat decimalFormat = new DecimalFormat("0.0");
middlePanelTextView.setText(decimalFormat.format(score.getElevationAngle()));
但是整数没有附加0

-18 should be -18.0 etc.
相反,我的值显示为
-18。

尝试使用

DecimalFormat decimalFormat = new DecimalFormat("#.#");

作为构造函数参数。请尝试使用以下代码:

DecimalFormat decimalFormat = new DecimalFormat("0.0#");
试一试


.@表示有效数字0不表示有效数字。
.#表示和可选数字,请尝试“##@”


我对语法不太清楚:但是上面的文章应该会提供您所需要的一切。

我的文本视图正在删除数字。是我的错。缩小字体大小。

是否有可能
middlePanelTextView
剪切文本?它是否正确显示-18.5?另外,您可以试试这个:
DecimalFormat-DecimalFormat=new-DecimalFormat(“0.0”,new-DecimalFormatSymbols(Locale.ENGLISH))
方法
score.getElevationAngle()
返回的值类型是什么?
score.getElevationAngle()
为我返回一个double值您的代码工作得很好,当给它一个值-18时返回-18.0。Sheehan Alam:)它完全按照liro说的那样工作。我已经测试过了。应该还有其他一些错误。请再读一遍操作,他想得到零,所以这里的模式是错误的。
middlePanelTextView.setText(""+decimalFormat.format(score.getElevationAngle()));