We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 99762ea commit d0554c1Copy full SHA for d0554c1
app/src/main/java/com/calculator/MyViewModel.kt
@@ -4,6 +4,7 @@ import android.util.Log
4
import androidx.lifecycle.MutableLiveData
5
import androidx.lifecycle.ViewModel
6
import net.objecthunter.exp4j.ExpressionBuilder
7
+import java.lang.Exception
8
9
class MyViewModel : ViewModel() {
10
@@ -30,11 +31,15 @@ class MyViewModel : ViewModel() {
30
31
Log.d("number", text)
32
val expression = ExpressionBuilder(text).build()
33
34
+ try {
35
val result = expression.evaluate()
36
if (Math.floor(result) == result)
37
answer.value = result.toString()
38
else
39
40
+ } catch (e: Exception) {
41
+ answer.value="Invalid"
42
+ }
43
}
44
45
private fun getFormatted(): String {
0 commit comments