帮助解决android数学问题 [英] Help with android math problem
本文介绍了帮助解决android数学问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图通过这个公式获得水流但是当我运行我的应用程序时,我得到64.52,我应该得到92.71。如果我在vb.net中运行相同的公式,它可以正常工作。总结一下,请看看我做得不对。
P.S.我刚刚开始学习Android。
谢谢。
Android代码
I am trying to get water flow with this formula but when I run my app I get 64.52 and I should get 92.71. If I run the same formula in vb.net it works fine. Can sum one please take a look and see what I'm not doing right.
P.S. I'm just starting to learn Android.
Thanks.
Android Code
public void buttonOnClick6(View v) {
try {
double B1 = 4 //Double.parseDouble(((EditText)findViewById(R.id.editText7)).getText().toString());
double Y1 = 3 //Double.parseDouble(((EditText)findViewById(R.id.editText8)).getText().toString());
double Z1 = 2 //Double.parseDouble(((EditText)findViewById(R.id.editText9)).getText().toString());
double N1 = 0.012 //Double.parseDouble(((EditText)findViewById(R.id.editText10)).getText().toString());
double S1 = 0.0003 //Double.parseDouble(((EditText)findViewById(R.id.editText11)).getText().toString());
double A1 = (B1 * Y1) + Z1 * pow(Y1, 2);//tbB * tbY;
double P1 = B1 + (2 * Y1) * pow((1 + pow(Z1, 2)), 0.5);//tbB + (2 * tbY);
double R1 = A1 / P1;
double CFS = ((1.49 / N1) * A1 * pow(R1, (2/3)) * pow(S1, 0.5));
double SEC1 = (CFS / A1);
TextView textElement3 = (TextView) findViewById(R.id.tb006);
textElement3.setText("Cross-Sect. Area, A = " + String.format("%.2f",A1));
TextView textElement4 = (TextView) findViewById(R.id.tb007);
textElement4.setText("Wetted Perimeter, P = " + String.format("%.2f",P1));
TextView textElement5 = (TextView) findViewById(R.id.tb008);
textElement5.setText("Hydraulic Radius, R = " + String.format("%.2f",R1));
TextView textElement1 = (TextView) findViewById(R.id.tbCFS1);
textElement1.setText("CFS: " + String.format("%.2f",CFS));
TextView textElement2 = (TextView) findViewById(R.id.tbSEC1);
textElement2.setText("FT/SEC: " + String.format("%.3f",SEC1));
} catch (Exception e) {
e.printStackTrace();
}
}
VB.NET代码此工作正常
VB.NET Code this work fine
Dim tbB1 As Double = 4
Dim tbY1 As Double = 3
Dim tbZ1 As Double = 2
Dim tbN1 As Double = 0.012
Dim tbS1 As Double = 0.0003
Dim A1 As Double = (tbB1 * tbY1) + tbZ1 * Pow(tbY1, 2)
Dim P1 As Double = tbB1 + (2 * tbY1) * Pow((1 + Pow(tbZ1, 2)), 0.5)
Dim R1 As Double = A1 / P1
Dim CFS1 As Double = (1.49 / tbN1) * A1 * Pow(R1, (2 / 3)) * Pow(tbS1, 0.5)
Dim FT_SEC1 As Double = CFS1 / A1
lbA.Content = "Cross-Sect. Area, A = " & A1
lbP.Content = "Wetted Perimeter, P = " & P1
lbR.Content = "Hydraulic Radius, R = " & R1
lbCFS.Content = "CFS: " & CFS1
lbFTSEC.Content = "FT/SEC: " & FT_SEC1
推荐答案
在SA和phil.o的评论的鼓励下,我试着给出答案。
将任何双常数写为double,表示不写x = 4,最好使用x = 4.0。
除了以下一些注释:
a。)尝试减少不需要使用()的地方。加法前的乘法仍然有效;)
b。)Pow(5 ,2/3)vs. Pow(5,2.0 / 3.0)你可以轻松检查VS c#
$ b的差异$ b Bruno
Encouraged by the comments of SA and phil.o, I try to give an answer.
Write any double constant as double, means don't write x= 4, better use x= 4.0.
Some notes besides:
a.) Try to reduce the useless use of "()" where it is not needed. Multiplication before Addition is still valid ;)
b.) Pow(5, 2/3) vs. Pow(5, 2.0/3.0) you can easy check the difference in VS c#
Bruno
这篇关于帮助解决android数学问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文