do not allow prepending some numbers with zero
This commit is contained in:
parent
b775a98247
commit
dc97c40b70
1 changed files with 18 additions and 1 deletions
|
@ -79,6 +79,17 @@ class CalculatorImpl(calculator: Calculator, val context: Context) {
|
|||
inputDisplayedFormula = ""
|
||||
}
|
||||
|
||||
val valueToCheck = if (inputDisplayedFormula.startsWith("-")) {
|
||||
inputDisplayedFormula.substring(1)
|
||||
} else {
|
||||
inputDisplayedFormula
|
||||
}
|
||||
|
||||
val value = valueToCheck.substring(valueToCheck.indexOfAny(operations, 0, false) + 1)
|
||||
if (value == "0" && number.toString().areDigitsOnly()) {
|
||||
inputDisplayedFormula = inputDisplayedFormula.dropLast(1)
|
||||
}
|
||||
|
||||
inputDisplayedFormula += number
|
||||
setValue(inputDisplayedFormula)
|
||||
}
|
||||
|
@ -287,7 +298,13 @@ class CalculatorImpl(calculator: Calculator, val context: Context) {
|
|||
}
|
||||
|
||||
private fun zeroClicked() {
|
||||
val value = inputDisplayedFormula
|
||||
val valueToCheck = if (inputDisplayedFormula.startsWith("-")) {
|
||||
inputDisplayedFormula.substring(1)
|
||||
} else {
|
||||
inputDisplayedFormula
|
||||
}
|
||||
|
||||
val value = valueToCheck.substring(valueToCheck.indexOfAny(operations, 0, false) + 1)
|
||||
if (value != "0") {
|
||||
addDigit(0)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue