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
2 changed files with 18 additions and 13 deletions

View File

@@ -127,21 +127,25 @@ class CalculatorImpl(calculator: Calculator, val context: Context) {
} }
fun handleClear() { fun handleClear() {
val oldValue = displayedNumber if (displayedNumber.equals(NAN)) {
var newValue = "0" handleReset()
val len = oldValue!!.length } else {
var minLen = 1 val oldValue = displayedNumber
if (oldValue.contains("-")) var newValue = "0"
minLen++ val len = oldValue!!.length
var minLen = 1
if (oldValue.contains("-"))
minLen++
if (len > minLen) { if (len > minLen) {
newValue = oldValue.substring(0, len - 1) 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() { fun handleReset() {

View File

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