So, I can divide fine using just whole numbers ie 73/15=4.8 it displays as 4 wich is fine, i dont mind that but when I need to divide say 73/7.5 it will crash the app. I was wondering if it has to do with using the class BigDecimal. I cant figure it out. Maybe you guys can help me.
http://pastebin.com/embed_iframe.php?i=esc2KG0Y
Not quite sure how to paste my code directly here either...
Just looking at it I can't see what could be wrong. Maybe try replacing BigDecimal with Double, and replace line 39 with:
result.setText(firstNum/secNum);
If you look at the API for BigDecimal, it states that "if the exact quotient cannot be represented (because it has a non-terminating decimal expansion) an ArithmeticException
is thrown."
To fix this, you have to add the MathContext parameter to the divide function...like so:
result.setText(firstNum.divide(secNum).toString(), new MathContext(5, RoundingMode.HALF_UP));
The first parameter in the MathContext constructor determines the precision of the decimal...and the second parameter determines how you are going to round the 5th number.
typecast the 73 as a float
Not quite sure but try using a double or float instead of an integer. (I don't speak java so the terms may be different.)
try setting a rounding method, as in:
divide(BigDecimal, RoundingMode)
for example:
bg3 = bg1.divide(bg2, RoundingMode.CEILING);
result.setText(firstNum.divide(secNum, RoundingMode.CEILING).toString());
See if that helps? my java is a little rusty, had to google there.