0

Is it possibly to read a double value from a string and evaluate it in java

16th Apr 2021, 1:56 PM
Bruck G/meskel
Bruck G/meskel - avatar
11 Answers
+ 5
String str = "0.5"; Double d; d = Double.parseDouble(str);
16th Apr 2021, 2:27 PM
Coding Cat
Coding Cat - avatar
+ 2
bruce Gmeskel Can you please give a detailed example. How does f(x) looks like?
16th Apr 2021, 3:35 PM
Denise Roßberg
Denise Roßberg - avatar
+ 2
Do you have a code where I can see it? Btw: If you want to replace x you should have a look into the StringBuilder class. StringBuilder is mutable and contains a replace method. https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/StringBuilder.html https://www.google.com/amp/s/www.geeksforgeeks.org/stringbuilder-class-in-java-with-examples/amp/
16th Apr 2021, 4:12 PM
Denise Roßberg
Denise Roßberg - avatar
0
Can you please give one example
16th Apr 2021, 2:04 PM
Atul [Inactive]
0
String str={"0.5"}; Double d; I wanted to store 0.5 into d
16th Apr 2021, 2:17 PM
Bruck G/meskel
Bruck G/meskel - avatar
0
Okay but i am trying to do a program that accept f(x) and evaluate it with an interval and i proceed with an infix evaluation method of stack but i cant accept a double value ?
16th Apr 2021, 2:34 PM
Bruck G/meskel
Bruck G/meskel - avatar
0
Any mathematical functions sucha as polynomial like X^3+x
16th Apr 2021, 3:40 PM
Bruck G/meskel
Bruck G/meskel - avatar
0
And which part of it is your wanted double value? Sorry I am not so good in math ;) But I guess you first need to split the String to separate each part of your function. And than it should be possible to get your double value.
16th Apr 2021, 3:51 PM
Denise Roßberg
Denise Roßberg - avatar
0
Yes that's right i separated intothe strings into char arr the i wantedvto replace the x variable by an interval or value so i tried to convert the interval which is double to string and store it on string but it only store the last value for instance 0.5 is my interval but it stores only 5
16th Apr 2021, 3:56 PM
Bruck G/meskel
Bruck G/meskel - avatar
16th Apr 2021, 4:22 PM
Bruck G/meskel
Bruck G/meskel - avatar
0
Thank you guys
18th Apr 2021, 6:09 AM
Bruck G/meskel
Bruck G/meskel - avatar