I am trying to figure out how to do two things :
- Change a number from a
Stringto adoubleand back to aString. - How to manipulate different parts of a
double.
To explain :
In the first case, I would like the user to be able to input a number into the a JTextArea so I can store the input in a variable (simple). Then, I would like to perform operations on the number that is inputted, but this cannot be done with a string. Is there any way to convert input into a double?
Then, I would like to take this string, after it has been converted into a double, and analyze the specific digits, and the digits of its decimal places (tenths, hundredths, etc.) as well using if-else and for statements (I can do this part). My understanding of strings is that, if I say NameofString[0], I will get the first letter of the string, but can this be done with a Number?
Lastly, I would like to convert this double back into a String.
You can parse a string using (assuming
xis a double variable andsa string)and convert the number back to a string via
If you want to format the value according to a specific format you may want to use
String.formatinstead.