当前位置: 动力学知识库 > 问答 > 编程问答 >

android - Java, math (adding, dividing, multiplying) all together

问题描述:

This is my code and it whines about calc 2 and the result.

BigDecimal costNum1 = new BigDecimal(number3.getText().toString());

BigDecimal costNum2 = new BigDecimal(number1.getText().toString());

BigDecimal costNum3 = new BigDecimal(number2.getText().toString());

BigDecimal calc1 = costNum1.multiply(costNum2);

BigDecimal calc2 = calc1.divide("100");

BigDecimal calc3 = calc2.multiply(costNum3);

result.setText(calc3).toString());

Safe to say I'm quite new in this, I'm almost there but I can't make up what is wrong. It's for my first Android App.

网友答案:

BigDecimal#divide accepts another BigDecimal, not a String.

Try

calc2.divide(new BigDecimal("100"));

Also, you have one too many parentheses in your last line.

Try

result.setText(calc3.toString());

You should always count the number of left parens, and see if it matches the number of right parens. If you use an IDE like eclipse, it should point these problems out to you automatically.

分享给朋友:
您可能感兴趣的文章:
随机阅读: