Basically i have a valued saved into shared preference as a string.
I am retrieving the value saved, and am trying to use it in a calculation.
How can i convert this so that it is seen as a double instead of a string?
Once the value is retrieved after the calculation, the new value is saved back into the sharedpreference under the same value.
I hope you can understand, been having trouble with this!
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
String newweight = sharedPreferences.getString("storednewweight", "");
newweight = newweight + 5;
//saves value into sharedpreference
savePreferences("storednewweight", (Double.toString(newweight)));
You can parse the string as a double:
A) If you don't need the double precision, use floats: getFloat and putFloat.
B) Parse the string as a double then save the double as a string again.
It can be saved as long like how I wrote it down:
Double to Long:
Long to Double:
EDIT:
Something like that should do it.