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();
        
        }
  • 相关阅读:
    新人入住博客,互相交流,互相进步
    DHCP技术
    一些额外技术
    OSPF技术
    一些常用的命令
    RSTP技术及原理
    BFD原理
    VRRP技术
    Super VLAN技术
    哈希表(HashMap)
  • 原文地址:https://www.cnblogs.com/sunxun/p/5969328.html
Copyright © 2011-2022 走看看