Formatting numbers using DecimalFormat

后端 未结 6 768
我寻月下人不归
我寻月下人不归 2021-01-01 21:05

I am trying to format prices using DecimalFormat, but this isn\'t working for all variations.

DecimalFormat df = new DecimalFormat(\"0.##\")
df.format(7.8)
d         


        
6条回答
  •  走了就别回头了
    2021-01-01 21:42

    I don't think it's possible, at least not with Java SE formatters. You need to make a custom formatter. I would do it like this

    String res = df.format(number).replace(".00", "");
    

提交回复
热议问题