show a clearshow a clearer error at zero division
This commit is contained in:
parent
3be6487fdd
commit
e4e24bc226
|
@ -163,8 +163,14 @@ class CalculatorImpl(calculator: Calculator, private val context: Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lastOperation != "") {
|
if (lastOperation != "") {
|
||||||
val expression = "${baseValue.format()}${getSign(lastOperation)}${secondValue.format()}".replace("√", "sqrt")
|
val sign = getSign(lastOperation)
|
||||||
|
val expression = "${baseValue.format()}$sign${secondValue.format()}".replace("√", "sqrt")
|
||||||
try {
|
try {
|
||||||
|
if (sign == "/" && secondValue == 0.0) {
|
||||||
|
context.toast(R.string.formula_divide_by_zero_error)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
val result = ExpressionBuilder(expression.replace(",", "")).build().evaluate()
|
val result = ExpressionBuilder(expression.replace(",", "")).build().evaluate()
|
||||||
showNewResult(result.format())
|
showNewResult(result.format())
|
||||||
baseValue = result
|
baseValue = result
|
||||||
|
|
Loading…
Reference in New Issue