Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/217.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String.format()无法在Android中使用EditText_Android_String - Fatal编程技术网

String.format()无法在Android中使用EditText

String.format()无法在Android中使用EditText,android,string,Android,String,我正在使用以下代码 Tx1XKBytes = (Tx1XBytes.doubleValue()/1024.0); //Tx1XKBytes is long variable BytesSent1X.setText(String.format("%.2f", Tx1XKBytes) +" KB"); //BytesSent1X is EdiText 我希望变量TX1xKB的精度达到两个小数点,比如23.46,但它不起作用。结果显示整个值,如23.467658。使用Ja

我正在使用以下代码

Tx1XKBytes = (Tx1XBytes.doubleValue()/1024.0);            //Tx1XKBytes is long variable
BytesSent1X.setText(String.format("%.2f", Tx1XKBytes) +" KB");   //BytesSent1X is EdiText 

我希望变量TX1xKB的精度达到两个小数点,比如23.46,但它不起作用。结果显示整个值,如23.467658。

使用Java中的DecimalFormat类,如:-

DecimalFormat mDecimalFormat = new DecimalFormat(".00");
它具有格式化十进制数字的格式化方法。

使用此格式

String.format("%1$,.2f", doubleValue);
如下

BytesSent1X.setText(String.format("%1$,.2f", Tx1XKBytes) +" KB");

长变量没有十进制分量-这是否意味着Tx1XKBytes实际上是一个
双精度
?我尝试过这个方法,但它也不适用于EditText。