zoukankan      html  css  js  c++  java
  • double的值太大,以及补0

    当double的值太大的时候,比如1000000000

    用DecimalFormat:
    
    double d = 1.0E7;
    System.out.println(new DecimalFormat("#").format(d));

     根据小数点位数补0

        /**取小数点位数补0
         * セルの書式(Format)
         * @param webFilePath
         */
        private String SetFormat(double maxValue){
            
            Integer Maxlenth = 0;
            StringBuilder value = new StringBuilder();
            if(maxValue !=0){
                DecimalFormat decimalFormat = new DecimalFormat("###############.########");  
                String strmaxValue =  decimalFormat.format(maxValue);
                String strpoint[]  =  strmaxValue.split("\.");
                if(strpoint.length >0){
                    int aaa =  strpoint[1].length();
                    //Maxlenth =   (maxValue+"").length()-(maxValue+"").indexOf(".")-1; 
                    Maxlenth = aaa; 
                }
            }
            if(Maxlenth > 0 ){
                for (int j = 0; j < Maxlenth; j++)
                {
                    if(j==0){
                        value.append(".0");
                    }else{
                        value.append("0");
                    }
                    
                } 
            }
            
            return value.toString();
        
        }
  • 相关阅读:
    LeetCode 260
    LeetCode 258
    LeetCode 237
    LeetCode 226
    LeetCode 203
    LeetCode 202
    codeforces 7D
    codefroces 7C
    codeforces 7B
    codeforces 6E (非原创)
  • 原文地址:https://www.cnblogs.com/sunxun/p/5969328.html
Copyright © 2011-2022 走看看