简体   繁体   中英

How can i use putdouble instead of put int

I wanna save the value of my textview in a onstop and onpause . But the value that is in the textview is a double , how can cast putint to double or use something else for it

This is my code How can i solve this?

     @Override
        protected void onStop()
        {
            super.onStop();
            savedValues.edit().putInt("price", (double)price).apply();
        }

Try storing a float but if loosing the precision is an Killing issue then consider storing that as String by calling the method putString

 putString (String key, String value)

and then parse that into a double

Double.parseDouble(myValueAsString); 

尝试这个

 savedValues.edit().putString("price",Double.parseDouble(price)).apply(); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM