mirror of
https://github.com/SimpleMobileTools/Simple-Calculator.git
synced 2025-06-05 21:49:13 +02:00
Fixed inserting zero after using clear
This commit is contained in:
@@ -288,9 +288,26 @@ class CalculatorImpl(calculator: Calculator, private val context: Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun handleClear() {
|
fun handleClear() {
|
||||||
|
val lastDeletedValue = inputDisplayedFormula.last().toString()
|
||||||
var newValue = inputDisplayedFormula.dropLast(1)
|
var newValue = inputDisplayedFormula.dropLast(1)
|
||||||
if (newValue == "") {
|
if (newValue == "") {
|
||||||
newValue = "0"
|
newValue = "0"
|
||||||
|
} else {
|
||||||
|
if (operations.contains(lastDeletedValue) || lastKey == EQUALS) {
|
||||||
|
lastOperation = ""
|
||||||
|
}
|
||||||
|
val lastValue = newValue.last().toString()
|
||||||
|
lastKey = when {
|
||||||
|
operations.contains(lastValue) -> {
|
||||||
|
CLEAR
|
||||||
|
}
|
||||||
|
lastValue == "." -> {
|
||||||
|
DECIMAL
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
DIGIT
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
newValue = newValue.trimEnd(',')
|
newValue = newValue.trimEnd(',')
|
||||||
|
Reference in New Issue
Block a user