日期:2014-05-20 浏览次数:21050 次
double d = 199.999;
String s = String.valueOf(d);
int index = s.indexOf(".");
String s1 = s.substring(0, index + 2).replace(".", ",");
System.out.println(s1);
------解决方案--------------------
for example
double d = 199.999;
String s = String.valueOf(d).replaceAll("(\\d+)[.](\\d)\\d+", "$1,$2");
System.out.println(s);
------解决方案--------------------
正解1111111111111
------解决方案--------------------
[color='red']11[/color ]
------解决方案--------------------
import java.util.*;
public class Test {
public static void main(String args[]) {
Locale de = new Locale("de","DE");//使用德国风俗。
Locale old = Locale.getDefault();
Locale.setDefault(de);
System.out.printf("Germany locale %.1f", 19.999-0.05);//java是四舍五入的,我没找到开关所以用个小技巧就能保证是舍去。
Locale.setDefault(old);
System.out.println();
System.out.printf("China locale %.1f", 19.999-0.05);//同上
}
}
------解决方案--------------------
+1