Java 计算误差

Java 计算误差,java,android,Java,Android,嗯 所以我希望这对外面的人来说应该是一个很简单的问题 程序运行良好,没有错误,没有崩溃,这是一个好的开始 问题是我得到了一个错误的答案 大约走了一半,你应该能看到那条线 CARV=CA*3;tv2.setText(Double.toString(CARV)) CA与用户输入的num3相关。因此,如果用户在editText2中输入100,则应将300打印到tv2。但是它给了我一个随机数,现在我假设它在打印答案之前考虑了上一行下面的额外计算 我的问题是,如何打印CA*3的答案 非常感谢 privat

所以我希望这对外面的人来说应该是一个很简单的问题

程序运行良好,没有错误,没有崩溃,这是一个好的开始

问题是我得到了一个错误的答案

大约走了一半,你应该能看到那条线

CARV=CA*3;tv2.setText(Double.toString(CARV))

CA
与用户输入的
num3
相关。因此,如果用户在
editText2
中输入100,则应将300打印到
tv2
。但是它给了我一个随机数,现在我假设它在打印答案之前考虑了上一行下面的额外计算

我的问题是,如何打印CA*3的答案

非常感谢

private OnClickListener myClickListener = new OnClickListener()
{
    public void onClick(View v) {
        try{
        NS=Double.parseDouble(num1.getText().toString()); 
        CH=Double.parseDouble(num2.getText().toString());
        CA=Double.parseDouble(num3.getText().toString());
        Z=Double.parseDouble(num4.getText().toString());
        EKW=Double.parseDouble(num5.getText().toString());
        FAT=Double.parseDouble(num6.getText().toString());
        CART=Double.parseDouble(num7.getText().toString());
        GAT=Double.parseDouble(num8.getText().toString());}
        catch(Exception e)
        {
            if(num1.getText().length()==0)
            {
                num1.setError("please input ");
            }
            if(num2.getText().length()==0)
            {
                num2.setError("please input ");
            }
            if(num3.getText().length()==0)
            {
                num3.setError("please ");
            }
            if(num4.getText().length()==0)
            {
                num4.setError("please ");
            }
            if(num5.getText().length()==0)
            {
                num5.setError("please input ");
            }
            if(num6.getText().length()==0)
            {
                num6.setError("please input ");
            }
            if(num7.getText().length()==0)
            {
                num7.setError("please input ");
            }
            if(num8.getText().length()==0)
            {
                num8.setError("please input ");
            }

        }

        {SV=(((NS*CH)*4)/3600)/Z;SV=(double)(Math.round(SV*100))/100; tv1.setText(Double.toString(SV));
        CARV= CA*3; tv2.setText(Double.toString(CARV));
        FA= SV*0.1;
        GA= SV - (CARV + FA);
        RCARA= CARV/SV;
        RGA= GA/SV;
        RFA= FA/SV;
        CAO=(CARV*RCARA) + (GA*RGA) + (FA*RFA);
        DT= 26-CAO;
        RKW= DT * 1.21 * SV;RKW=(double)(Math.round(RKW*100))/100; tv3.setText(Double.toString(RKW));
        }

    }
};
    @Override
    public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.car1);

       tv1 = (TextView)findViewById(R.id.textView7);
       tv2 = (TextView)findViewById(R.id.textView8);
       tv3 = (TextView)findViewById(R.id.textView8);


       button01 = (Button)findViewById(R.id.button1);
       button01.setText("Display result");
       button01.setOnClickListener(myClickListener);

       num1 = (EditText)findViewById(R.id.EditText01);
       num1.setText("");
       num2 = (EditText)findViewById(R.id.editText1);
       num2.setText("");
       num3 = (EditText)findViewById(R.id.editText2);
       num3.setText("");
       num4 = (EditText)findViewById(R.id.editText3);
       num4.setText("");
       num5 = (EditText)findViewById(R.id.editText4);
       num5.setText("");
       num6 = (EditText)findViewById(R.id.editText5);
       num6.setText("-5");
       num7 = (EditText)findViewById(R.id.editText6);
       num7.setText("10");
       num8 = (EditText)findViewById(R.id.editText7);
       num8.setText("16");          
    }

}我想你的问题就在这里

tv2 = (TextView)findViewById(R.id.textView8);
tv3 = (TextView)findViewById(R.id.textView8);

您将相同的文本视图分配给
tv2
tv3

您确认了
CA
的值是您所期望的吗?请随意使用空白。您当前的代码在某些地方(特别是关键部分)有点纠结,这使得它有点难以阅读。你使用的非标准命名。很好地发现。。。愚蠢的打字错误。。。再次感谢。