Merge pull request #55 from ensozos/Issue#54

[Bug] NaN error #54
This commit is contained in:
Tibor Kaputa 2018-01-06 14:28:33 +01:00 committed by GitHub
commit 23201138ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 13 deletions

View File

@ -127,21 +127,25 @@ class CalculatorImpl(calculator: Calculator, val context: Context) {
}
fun handleClear() {
val oldValue = displayedNumber
var newValue = "0"
val len = oldValue!!.length
var minLen = 1
if (oldValue.contains("-"))
minLen++
if (displayedNumber.equals(NAN)) {
handleReset()
} else {
val oldValue = displayedNumber
var newValue = "0"
val len = oldValue!!.length
var minLen = 1
if (oldValue.contains("-"))
minLen++
if (len > minLen) {
newValue = oldValue.substring(0, len - 1)
if (len > minLen) {
newValue = oldValue.substring(0, len - 1)
}
newValue = newValue.replace("\\.$".toRegex(), "")
newValue = formatString(newValue)
setValue(newValue)
mBaseValue = Formatter.stringToDouble(newValue)
}
newValue = newValue.replace("\\.$".toRegex(), "")
newValue = formatString(newValue)
setValue(newValue)
mBaseValue = Formatter.stringToDouble(newValue)
}
fun handleReset() {

View File

@ -13,6 +13,7 @@ val DECIMAL = "decimal"
val CLEAR = "clear"
val RESET = "reset"
val NAN = "NaN"
val ZERO = "zero"
val ONE = "one"
val TWO = "two"