Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Executing math equation in Android

I need to be able to handle a math equation such as "(45+9)/8" in my app. I wanted to just eval it using JavaScript, but realized that I can't use javax.script in Android. So, I found WebView, but I'm having a bit of trouble using it. Most of the examples refer to using an external page with the JS code, or using "javascript: var return ...etc." I'd need to use the latter, but I've been having a bit of trouble with returning the variable to my app.

Is it possible to have the JS eval it and then write the value to a hidden TextView?

like image 673
Rhyono Avatar asked Apr 05 '12 04:04

Rhyono


People also ask

How do you do math formulas on Android?

Write equationsTap Home and select Insert. Under Insert, choose Insert New Equation. You get the prompt to type a new equation. After you type your equation in linear format, tap to see Math Options.

How do you display math formulas and apps in Android?

Although there is no direct way to show math formula in android TextView, But you can use MathJaxWebView and use the webview to show formula using it. Visit the link for more infomation on how to do it. Show activity on this post. *You can use MathJax also but it is slightly heavy.

What is equatio in math?

Equatio allows you to create equations, formulas, and more, digitally. Helping to make math and STEM classes more accessible and engaging for every student. Try Equatio. Google Chrome. Web App.


1 Answers

Check out exp4j. It's a simple expression evaluator for java. For the equation you posted in your question you could just do:

Calculable calc = new ExpressionBuilder("(45+9)/8").build()
double result1=calc.calculate();
like image 173
Kurtis Nusbaum Avatar answered Sep 22 '22 03:09

Kurtis Nusbaum