所以输出“H”在这给了我太长的数字,小数点在错误的位置,但否则整数是正确的。例如:
#include <iostream>
using namespace std;
int sum(int int1, int int2 ){
return int1 + int2;
}
int difference( int int1, int int2 ){
return int1 - int2;
}
int product( int int1, int int2 ){
return int1 * int2;
}
int quotient( int int1, int int2 ){
return int1 / int2;
}
int main(){
cout << "\nWelcome to the calculator.\n\n";
cout << "Please enter two numbers.\n\n";
int a;
int b;
cin >> a >> b;
cout << "What would you like to do with these numbers?\nHere are your options: add, subtract, multiply, or divide.\n\n";
string add;
string subtract;
string multiply;
string divide;
string choice;
cin >> choice;
if( choice == add )
cout << sum( a, b );
else if ( choice == subtract )
cout << difference( a, b );
else if ( choice == multiply )
cout << product( a, b );
else if ( choice == divide )
cout << quotient( a, b );
else
cout << "Invalid entry.\n";
return 0;
}
是显示的内容
应显示<img>
我怀疑结果是
333433.33333
但是当我将其更改为333.43
时,它似乎没有帮助。
`h = (double) Math.round(h * 100000) / 100000;`
答案 0 :(得分:0)
根据我的理解,h
关闭了1000倍,而您的TextView
显示的小数点太多。我建议:
1)在h
中将Calculate_H
除以1000。 (即return h / 1000
)
2)使用String.format
显示小数点后的所需位数。例如,txtAnswer.setText(String.format("H = %.2f", Calculate_H(F, A, C)))
将在小数点后显示2位数。