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

后端 未结 5 1041
时光取名叫无心
时光取名叫无心 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条回答
  •  情歌与酒
    2020-12-16 01:23

    You can also try something like

    DecimalFormat df = new DecimalFormat("#,###.00");
    
    System.out.println(df.format(1200.20));
    System.out.println(df.format(15000));
    System.out.println(df.format(123456789.99));
    
    1,200.20
    15,000.00
    123,456,789.99
    

提交回复
热议问题