excel可以自定义格式
15360105.64如果显示为15.4,代码为 #,###.0,,我想问:JAVA的DecimalFormat 模式,需要怎么写代码?好象“,”不能放在小数点后面

解决方案 »

  1.   


    import java.text.*;public class NumberFormatDemo{
    public static void main(String[] args){
         int i = 9;
         float f = 9.8f;
         double d = 7.8677;
        
         NumberFormat nf = new DecimalFormat();
         nf.setMaximumFractionDigits(2);
         nf.setMinimumFractionDigits(2);
        
         System.out.println ( nf.format(i) );
         System.out.println ( nf.format(f) );
         System.out.println ( nf.format(d) );
        
        }
    }
      

  2.   

    谢谢楼上的,其实我是想要“#,###.0,,”这样的表达式写法,而不是JAVA代码