java-双精度数据计算和展示

 java 精确计算并返回非科学计数法字符串

高精度计算,一般使用double或者bigdecimal;

使用双精度Double方式如下:

        // 第一步 将数字转化为Double格式

        Double a = Double.valueOf(("0000001110000.01")); //高并发下,计算对象使用内存堆,保证数据的唯一性;
        Double b = Double.valueOf(("0000001110022.02"));
       

        // 第二步 运算
        Double c = a + b;

        //第三步将Double 数据转化为字符串

       String r = tranToString(c, 2);

   public static String tranToString(Double input, int fractionDigits){
        NumberFormat numberFormat = NumberFormat.getInstance();
        numberFormat.setGroupingUsed(false); //不分组
        numberFormat.setMaximumFractionDigits(fractionDigits);//最大小数长度
        numberFormat.setMinimumFractionDigits(fractionDigits);//最小小数长度
        return numberFormat.format(input);
    }

 

 

你可能感兴趣的:(java-基础)