我正在创建一个应用程序中编写一个公式。这包括倍增。我设法将BigDecimals相乘,但无法弄清楚如何使用整数执行此操作。这是我的java代码。
public void onClick(View v) {
//Get string items in spinners and store them in string variables
String string1 = weightSpinner.getSelectedItem().toString();
String string2 = genderSpinner.getSelectedItem().toString();
String string3 = amountSpinner.getSelectedItem().toString();
String string4 = hoursSpinner.getSelectedItem().toString();
//Declare string variables and Big Decimals
BigDecimal num1 = new BigDecimal(string1);
BigDecimal num2 = new BigDecimal(string2);
BigDecimal num3 = new BigDecimal(string3);
Integer num4 = new Integer(string4);
//Formula: // BAC = ([Alcohol consumed in grams/(Body weight in grams*Gender constant)]*100) – Time passed
if (drinkSpinner.getSelectedItem().toString().equals("Beer")){ //&& (amountSpinner.getSelectedItem().toString().equals("568.261"))) {
num1.multiply(num2).divide(num3).subtract(num4);//My error is with num4 as it is an integer
}
请告诉我如何使用java代码解决此问题。感谢。
答案 0 :(得分:0)
你可以使用num1.multiply(num2).divide(num3).subtract(new BigDecimal(num4));