Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/341.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 Android:计算器中的结果显示整数(需要浮点/双精度)_Java_Android_Int_Calculator - Fatal编程技术网

Java Android:计算器中的结果显示整数(需要浮点/双精度)

Java Android:计算器中的结果显示整数(需要浮点/双精度),java,android,int,calculator,Java,Android,Int,Calculator,我为学习java编写了android计算器,但在应用程序中出现了一个错误。若我输入5/3-答案是2,但我需要浮动结果(1,6)。我需要改变什么 ArrayList<Float> result = new ArrayList<Float>(); float number1; float number2; calcDialogDisplay = (TextView) findViewById(R.id.tvResult); pub

我为学习java编写了android计算器,但在应用程序中出现了一个错误。若我输入5/3-答案是2,但我需要浮动结果(1,6)。我需要改变什么

    ArrayList<Float> result = new ArrayList<Float>();

    float number1;
    float number2;

    calcDialogDisplay = (TextView) findViewById(R.id.tvResult);

    public void DIVISION(){
    number1 = result.get(0);
    number2 = result.get(1);

    result.removeAll(result);

    result.add(number1 / number2);

    calcDialogDisplay.setText(String.format("%.0f", result.get(0)));
}
ArrayList结果=新建ArrayList();
浮点数1;
浮点数2;
calcDialogDisplay=(TextView)findViewById(R.id.tvResult);
公共事务部(){
number1=结果。获取(0);
number2=结果。获取(1);
result.removeAll(result);
结果。添加(编号1/2);
calcDialogDisplay.setText(String.format(“%.0f”,result.get(0));
}
试试:


更多信息(部分:浮点转换)。

请阅读
String.format
文档。。。。你只是得到了你想要的-0小数位输出1.6不是真的。。。1.7
calcDialogDisplay.setText(String.format("%.1f", result.get(0)));  // should output 1.7