简体   繁体   English

我如何使用putdouble而不是put int

[英]How can i use putdouble instead of put int

I wanna save the value of my textview in a onstop and onpause . 我想在onstoponpause保存textview的值。 But the value that is in the textview is a double , how can cast putint to double or use something else for it 但是textview的值是double ,如何将putintdouble或对其使用其他内容

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

 putString (String key, String value)

and then parse that into a double 然后将其解析为一个double

Double.parseDouble(myValueAsString); 

尝试这个

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我如何使用 int 而不是使用 Integer? - How can i use an int instead of using Integer? 我如何在扫描仪中使用 Int 的值 - How Can i Use The Values Of The Int in The Scanner JNI我可以使用哪些类型而不是给定(unsigned int,const char *,const wchar_t *,...) - JNI what types can I use instead of given (unsigned int, const char*, const wchar_t*, … ) 我怎么能把我的私人 int 放入公共 int - How could I put my private int into the public int 如何使用long而不是int可以防御以下方法 - Effective Java - How use long instead of int can bulletproof the following method - Effective Java 如何使用数组列表中的索引并转换为 int? - How can I use the index in my array list and convert to int? 如何在 Java 的 get 和 return 方法中使用 input(int)? - How can i use input(int) in get and return method in Java? 如何在Java中使用fill(int [] a,int from_Index,int to_Index,int val)用于矩阵? - how can I use fill(int[] a, int from_Index, int to_Index, int val) for matrix in Java? 如何让用户输入一个int值并将它们拆分为单个数字并放入数组? - How can I make user to input an int value and split them up to single number and put in array? 如何返回多个变量和/或使用私有int方法? - How can I return multiple variables and/or use a private int method?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM