关于java需要控制double类型小数点后的位数,


[c-sharp]  view plain  copy
  1. import java.text.DecimalFormat;  
  2.   
  3. public class Main {  
  4.     public static void main(String[] args) {  
  5.                DecimalFormat df = new DecimalFormat( "0.0000 ");  
  6.                double d1 = 1.0;  
  7.                double d2 = 4.56789;  
  8.                System.out.println(df.format(d1));   
  9.                System.out.println(df.format(d2));   
  10.         }  
  11. }  

猜你喜欢

转载自blog.csdn.net/yilongdashi/article/details/80453612
今日推荐