Java: double: how to ALWAYS show two decimal digits

后端 未结 6 1981
悲&欢浪女
悲&欢浪女 2021-02-03 23:23

I use double values in my project and I would like to always show the first two decimal digits, even if them are zeros. I use this function for rounding and if the value I print

6条回答
  •  难免孤独
    2021-02-03 23:42

    java.text.DecimalFormat df = new java.text.DecimalFormat("###,###.##");
    df.setMaximumFractionDigits(2); 
    df.setMinimumFractionDigits(2); 
    

提交回复
热议问题