replace * with × and / with ÷

This commit is contained in:
tibbi 2020-12-28 21:03:39 +01:00
parent cf45c237bc
commit a5ec64f6f9

View File

@ -13,8 +13,8 @@ class CalculatorImpl(calculator: Calculator, private val context: Context) {
private var inputDisplayedFormula = "0" private var inputDisplayedFormula = "0"
private var lastKey = "" private var lastKey = ""
private var lastOperation = "" private var lastOperation = ""
private val operations = listOf("+", "-", "*", "/", "^", "%", "") private val operations = listOf("+", "-", "×", "÷", "^", "%", "")
private val operationsRegex = "[-+*/^%√]".toPattern() private val operationsRegex = "[-+×÷^%√]".toPattern()
private val numbersRegex = "[^0-9,.]".toRegex() private val numbersRegex = "[^0-9,.]".toRegex()
init { init {
@ -100,7 +100,7 @@ class CalculatorImpl(calculator: Calculator, private val context: Context) {
calculateResult() calculateResult()
if (!operations.contains(inputDisplayedFormula.last().toString())) { if (!operations.contains(inputDisplayedFormula.last().toString())) {
if (!inputDisplayedFormula.contains("/")) { if (!inputDisplayedFormula.contains("÷")) {
inputDisplayedFormula += getSign(operation) inputDisplayedFormula += getSign(operation)
} }
} }
@ -167,9 +167,9 @@ class CalculatorImpl(calculator: Calculator, private val context: Context) {
if (lastOperation != "") { if (lastOperation != "") {
val sign = getSign(lastOperation) val sign = getSign(lastOperation)
val expression = "${baseValue.format()}$sign${secondValue.format()}".replace("", "sqrt") val expression = "${baseValue.format()}$sign${secondValue.format()}".replace("", "sqrt").replace("×", "*").replace("÷", "/")
try { try {
if (sign == "/" && secondValue == 0.0) { if (sign == "÷" && secondValue == 0.0) {
context.toast(R.string.formula_divide_by_zero_error) context.toast(R.string.formula_divide_by_zero_error)
return return
} }
@ -178,7 +178,7 @@ class CalculatorImpl(calculator: Calculator, private val context: Context) {
showNewResult(result.format()) showNewResult(result.format())
baseValue = result baseValue = result
inputDisplayedFormula = result.format() inputDisplayedFormula = result.format()
showNewFormula(expression.replace("sqrt", "")) showNewFormula(expression.replace("sqrt", "").replace("*", "×").replace("/", "÷"))
} catch (e: Exception) { } catch (e: Exception) {
context.toast(R.string.unknown_error_occurred) context.toast(R.string.unknown_error_occurred)
} }
@ -243,8 +243,8 @@ class CalculatorImpl(calculator: Calculator, private val context: Context) {
private fun getSign(lastOperation: String) = when (lastOperation) { private fun getSign(lastOperation: String) = when (lastOperation) {
MINUS -> "-" MINUS -> "-"
MULTIPLY -> "*" MULTIPLY -> "×"
DIVIDE -> "/" DIVIDE -> "÷"
PERCENT -> "%" PERCENT -> "%"
POWER -> "^" POWER -> "^"
ROOT -> "" ROOT -> ""