Add commas (grouping separator) to number without modifying decimals?

后端 未结 5 1038
时光取名叫无心
时光取名叫无心 2020-12-16 00:55

I\'m trying to format a string to add commas between 3 digit groups

EG:

1200.20 >> 1,200.20
15000   >> 15,000

I\'m tryi

5条回答
  •  -上瘾入骨i
    2020-12-16 01:27

    You should be able to do exactly what you want:

    http://docs.oracle.com/javase/tutorial/i18n/format/decimalFormat.html

    DecimalFormat myFormatter = new DecimalFormat("$###,###.###");
    String output = myFormatter.format(12345.67);
    System.out.println(value + " " + pattern + " " + output);
    

提交回复
热议问题