0

I am writing a formula in an app I am creating. This includes multiplying. I have managed to multiply BigDecimals but cannot figure out how to do this with an integer. Here is my java code.

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
                  }

Please let me know how to get around this problem with java code. Thanks.

1 Answers1

0

You can use num1.multiply(num2).divide(num3).subtract(new BigDecimal(num4));