1

我是 Android 开发人员。我从网络服务结果 45.0000 中获得。我存储了 ArrayList。但我只想在两位数之后显示它。

仅示例输出 45.00。请给我解决方案。

4

2 回答 2

2

使用DecimalFormat类来实现这一点。

DecimalFormat df=new DecimalFormat("##.##");
String formate = df.format(value); 
double finalValue = (Double)df.parse(formate) ;
于 2013-03-13T14:38:44.193 回答
0

你可以使用String.format,它使用指定的格式字符串和参数返回一个格式化的字符串

String.format("$%.2f", value);

String.format使用您的Locale

整数索引 = 0;for (; index < yourList.size (); index++) { String tmpvalue = yourList.get(index); String conValue = String.format("$%.2f", Float.parse(tmpvalue)); yourList.set(index, conValue); 索引++;}

于 2013-03-13T15:04:46.887 回答