mirror of
https://github.com/SimpleMobileTools/Simple-Calculator.git
synced 2025-06-05 21:49:13 +02:00
handle thousands delimiter at Clear too
This commit is contained in:
@@ -28,19 +28,7 @@ class CalculatorImpl(calculator: Calculator, private val context: Context) {
|
||||
}
|
||||
|
||||
inputDisplayedFormula += number
|
||||
|
||||
val valuesToCheck = numbersRegex.split(inputDisplayedFormula).filter { it.trim().isNotEmpty() }
|
||||
valuesToCheck.forEach {
|
||||
var newString = Formatter.addGroupingSeparators(it)
|
||||
|
||||
// allow writing numbers like 0.003
|
||||
if (it.contains(".")) {
|
||||
newString = newString.substringBefore(".") + ".${it.substringAfter(".")}"
|
||||
}
|
||||
|
||||
inputDisplayedFormula = inputDisplayedFormula.replace(it, newString)
|
||||
}
|
||||
|
||||
addThousandsDelimiter()
|
||||
showNewResult(inputDisplayedFormula)
|
||||
}
|
||||
|
||||
@@ -67,6 +55,19 @@ class CalculatorImpl(calculator: Calculator, private val context: Context) {
|
||||
showNewResult(inputDisplayedFormula)
|
||||
}
|
||||
|
||||
private fun addThousandsDelimiter() {
|
||||
val valuesToCheck = numbersRegex.split(inputDisplayedFormula).filter { it.trim().isNotEmpty() }
|
||||
valuesToCheck.forEach {
|
||||
var newString = Formatter.addGroupingSeparators(it)
|
||||
// allow writing numbers like 0.003
|
||||
if (it.contains(".")) {
|
||||
newString = newString.substringBefore(".") + ".${it.substringAfter(".")}"
|
||||
}
|
||||
|
||||
inputDisplayedFormula = inputDisplayedFormula.replace(it, newString)
|
||||
}
|
||||
}
|
||||
|
||||
fun handleOperation(operation: String) {
|
||||
if (inputDisplayedFormula == "") {
|
||||
inputDisplayedFormula = "0"
|
||||
@@ -183,7 +184,8 @@ class CalculatorImpl(calculator: Calculator, private val context: Context) {
|
||||
|
||||
newValue = newValue.trimEnd(',')
|
||||
inputDisplayedFormula = newValue
|
||||
showNewResult(newValue)
|
||||
addThousandsDelimiter()
|
||||
showNewResult(inputDisplayedFormula)
|
||||
}
|
||||
|
||||
fun handleReset() {
|
||||
|
Reference in New Issue
Block a user