double的值太大,以及补0

本文介绍了一种使用Java DecimalFormat类来格式化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();
    
    }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值