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
|
inputDisplayedFormula += number
|
||||||
|
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
showNewResult(inputDisplayedFormula)
|
showNewResult(inputDisplayedFormula)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,6 +55,19 @@ class CalculatorImpl(calculator: Calculator, private val context: Context) {
|
|||||||
showNewResult(inputDisplayedFormula)
|
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) {
|
fun handleOperation(operation: String) {
|
||||||
if (inputDisplayedFormula == "") {
|
if (inputDisplayedFormula == "") {
|
||||||
inputDisplayedFormula = "0"
|
inputDisplayedFormula = "0"
|
||||||
@@ -183,7 +184,8 @@ class CalculatorImpl(calculator: Calculator, private val context: Context) {
|
|||||||
|
|
||||||
newValue = newValue.trimEnd(',')
|
newValue = newValue.trimEnd(',')
|
||||||
inputDisplayedFormula = newValue
|
inputDisplayedFormula = newValue
|
||||||
showNewResult(newValue)
|
addThousandsDelimiter()
|
||||||
|
showNewResult(inputDisplayedFormula)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun handleReset() {
|
fun handleReset() {
|
||||||
|
Reference in New Issue
Block a user