码迷,mamicode.com
首页 > 其他好文 > 详细

科学计数法转发成浮点数表示

时间:2019-08-23 13:26:38      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:use   value   tostring   action   des   str   author   int   pre   

private Double scientDouble;

    public Double getScientDouble() {
        return scientDouble;
    }

    public void setScientDouble(Double scientDouble) {
        this.scientDouble = scientDouble;
    }

    /**
     * @description:给Double类型赋值过大,或者过小时产生科学计数法.
     * 把科学计数法转换成浮点数表示
     * @author: 
     * @date: 2019/8/21
     * @param null:
     * @return: 
     */
    public static String scientificCountToFloat(Double scientStr){
        System.out.println(scientStr);
        String str[]=scientStr.toString().split("-");
        for (int i = 0; i <str.length ; i++) {
            System.out.println(str[i]);
        }
        NumberFormat nf = NumberFormat.getInstance();
        //设置小数位数,通过算出科学计数法的小数位数,然后设置小数位数
        if (str.length>1){
            nf.setMaximumFractionDigits(Integer.valueOf(str[1]));
        }

        //取消科学计数法
        nf.setGroupingUsed(false);
        return nf.format(scientStr);
    }

 public static void main(String[] args) {
        MathUtil mathUtil=new MathUtil();
        mathUtil.setScientDouble(0.00000000000000000001);
        System.out.println(scientificCountToFloat(mathUtil.getScientDouble()););
    }

 

科学计数法转发成浮点数表示

标签:use   value   tostring   action   des   str   author   int   pre   

原文地址:https://www.cnblogs.com/cyoba/p/11399352.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!