Skip to content

Commit 4cb9b8d

Browse files
authored
fix: prevent invalid state after percentage calculation (#178)
Refs: #160
1 parent e5b8fe5 commit 4cb9b8d

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
### Fixed
10+
- Fixed issue that occurs after doing a percent operation ([#160])
11+
912
## [1.2.0] - 2025-10-29
1013
### Changed
1114
- Compatibility updates for Android 15 & 16
@@ -60,6 +63,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6063
[#31]: https://github.com/FossifyOrg/Calculator/issues/31
6164
[#44]: https://github.com/FossifyOrg/Calculator/issues/44
6265
[#64]: https://github.com/FossifyOrg/Calculator/issues/64
66+
[#160]: https://github.com/FossifyOrg/Calculator/issues/160
6367

6468
[Unreleased]: https://github.com/FossifyOrg/Calculator/compare/1.2.0...HEAD
6569
[1.2.0]: https://github.com/FossifyOrg/Calculator/compare/1.1.0...1.2.0

app/src/main/kotlin/org/fossify/math/helpers/CalculatorImpl.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ class CalculatorImpl(
114114
if (lastKey == DIGIT || lastKey == DECIMAL) {
115115
if (lastOperation != "" && operation == PERCENT) {
116116
handlePercent()
117+
lastOperation = ""
117118
} else {
118119
// split to multiple lines just to see when does the crash happen
119120
secondValue = when (operation) {
@@ -140,7 +141,7 @@ class CalculatorImpl(
140141
if (getSecondValue() == BigDecimal.ZERO && inputDisplayedFormula.contains("÷")) {
141142
lastKey = DIVIDE
142143
lastOperation = DIVIDE
143-
} else {
144+
} else if(operation != PERCENT) {
144145
lastKey = operation
145146
lastOperation = operation
146147
}
@@ -376,6 +377,7 @@ class CalculatorImpl(
376377
if (newValue == "" || newValue == "0") {
377378
newValue = "0"
378379
lastKey = CLEAR
380+
resetValues()
379381
} else {
380382
if (operations.contains(lastDeletedValue) || lastKey == EQUALS) {
381383
lastOperation = ""

0 commit comments

Comments
 (0)