使用全部替换将不起作用。当你需要的是找到'.'的最后一次出现。或“,”并将其用作您的小数位。
基于http://docs.oracle.com/javase/tutorial/i18n/format/decimalFormat.html
public static void main(String... args) throws ParseException {
DecimalFormatSymbols dfs1 = new DecimalFormatSymbols();
dfs1.setDecimalSeparator('.');
dfs1.setGroupingSeparator(',');
DecimalFormat df1 = new DecimalFormat("#,##0.00", dfs1);
System.out.println(df1.format(-10000)+" parsed is "+df1.parse("-10,000.01"));
DecimalFormatSymbols dfs2 = new DecimalFormatSymbols();
dfs2.setDecimalSeparator(',');
dfs2.setGroupingSeparator('.');
DecimalFormat df2 = new DecimalFormat("#,##0.00", dfs2);
System.out.println(df2.format(-10000)+" parsed is "+df2.parse("-10.000,01"));
}
印刷
-10,000.00 parsed is -10000.01
-10.000,00 parsed is -10000.01