java 给定字符串12345678.89 输出$12,345,678,89

2025-01-24 06:41:32
推荐回答(1个)
回答1:

String s = "12345678.89" ;
NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US);
NumberFormat nfc = NumberFormat.getCurrencyInstance(Locale.CHINA);

System.out.println(nf.format(Double.parseDouble(s)));
System.out.println(nfc.format(Double.parseDouble(s)));

自己试一下