问题
Hello I'm a beginner in Android programming. I'm working on a graphic calculator but i still have the problem of converting the function to math
For example :
y=cos(x^2)-ln(x)
should look like
y=Math.cos(x*x) - Math.log(x)
And than we plot it.
Thank You
回答1:
I assume you want to convert a String to a float or double?
String input = "3.14";
float x = Float.parseFloat(input);
This code converts the String "3.14" into a float. You can use this float in the function you described in the question.
EDIT: If you want to convert the full function String into Java code, you should limit the input to buttons. For example, add a button named "Cos", and remember in the code the user wants to use the Cosinus function. Then the user enters a value, and presses "Enter". The code knows it should use the cosinus function, and x is the value entered in an EditText. That value should be parsed using Float.parseFloat().
来源:https://stackoverflow.com/questions/21137526/convert-a-string-into-mathematical-function-of-x-fx