基本的帝国转换问题

Sea*_*ean 4 java math android

为我的android编码计算工具.在输入上是英尺和英寸的距离.

我有两个分别为英尺和英寸的输入(input3和input4).在我的计算中,我试图将这两个输入转换为十进制数,以便在等式的其余部分中使用.这是我的代码中执行此操作的部分:

private void doCalculation() { 
    // Get entered input value 
    String strValue3 = input3.getText().toString(); 
    String strValue4 = input4.getText().toString();

    // Perform a hard-coded calculation 
    double imperial1 = (Integer.parseInt(strValue3) + (Integer.parseInt(strValue4) / 12));

    // Update the UI with the result to test if calc worked 
    output2.setText("Test: "+ imperial1); 
}
Run Code Online (Sandbox Code Playgroud)

我的测试值是4英尺6英寸.这个4很好,但是当它除以12时,6英寸默认为0.所以我的结果是4.0我尝试将计算减少到JUST分割操作,结果是0.0

我究竟做错了什么?(fyi:这是我第一次使用Java)

Eli*_*Eli 8

你的类型错了.当你真的应该加倍时,你将它们解析为int.

尝试:

double imperial1 = Double.parseDouble(strValue3) + 
    (Double.parseDouble(strValue4) / 12.0);
Run Code Online (Sandbox Code Playgroud)