mirror of
https://github.com/SimpleMobileTools/Simple-Calculator.git
synced 2025-06-05 21:49:13 +02:00
fix the bug of % and pass the test case percentageTest
This commit is contained in:
@ -13,7 +13,6 @@ class CalculatorImpl(calculator: Calculator, val context: Context) {
|
|||||||
|
|
||||||
private var mIsFirstOperation = false
|
private var mIsFirstOperation = false
|
||||||
private var mResetValue = false
|
private var mResetValue = false
|
||||||
private var mWasPercentLast = false
|
|
||||||
private var mBaseValue = 0.0
|
private var mBaseValue = 0.0
|
||||||
private var mSecondValue = 0.0
|
private var mSecondValue = 0.0
|
||||||
|
|
||||||
@ -62,9 +61,6 @@ class CalculatorImpl(calculator: Calculator, val context: Context) {
|
|||||||
setFormula(first + sign)
|
setFormula(first + sign)
|
||||||
} else if (!sign.isEmpty()) {
|
} else if (!sign.isEmpty()) {
|
||||||
var formula = first + sign + second
|
var formula = first + sign + second
|
||||||
if (mWasPercentLast) {
|
|
||||||
formula += "%"
|
|
||||||
}
|
|
||||||
setFormula(formula)
|
setFormula(formula)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -111,9 +107,6 @@ class CalculatorImpl(calculator: Calculator, val context: Context) {
|
|||||||
|
|
||||||
private fun calculateResult() {
|
private fun calculateResult() {
|
||||||
updateFormula()
|
updateFormula()
|
||||||
if (mWasPercentLast) {
|
|
||||||
mSecondValue *= mBaseValue / 100
|
|
||||||
}
|
|
||||||
|
|
||||||
val operation = OperationFactory.forId(mLastOperation!!, mBaseValue, mSecondValue)
|
val operation = OperationFactory.forId(mLastOperation!!, mBaseValue, mSecondValue)
|
||||||
if (operation != null) {
|
if (operation != null) {
|
||||||
@ -124,7 +117,6 @@ class CalculatorImpl(calculator: Calculator, val context: Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun handleOperation(operation: String) {
|
fun handleOperation(operation: String) {
|
||||||
mWasPercentLast = operation == PERCENT
|
|
||||||
if (lastKey == DIGIT && operation != ROOT && operation != FACTORIAL) {
|
if (lastKey == DIGIT && operation != ROOT && operation != FACTORIAL) {
|
||||||
handleResult()
|
handleResult()
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user