zoukankan      html  css  js  c++  java
  • 20_BigDecimal类 BigInteger类 (较大的小数、非常大的大整数)

    BigDecimal类 BigInteger类:

    BigDecimal类 (大数据中的较大的小数)

    BigInteger类(大数据中的非常大的大整数)

    BigDecimal类:

    复制代码
    //有些时候操作小数的时候,会出现精度损失问题
    //加,减,乘,除   四则运算
         System.out.println(0.09+0.01);//0.1 -->0.09999999999999999999999999 System.out.println(1.231 * 100);// 123.1--->123.100000000000000000001 //大小数四则运算 加减乘除 BigDecimal decimal1 = new BigDecimal("0.09"); BigDecimal decimal2 = new BigDecimal("0.01"); //相加运算 add() BigDecimal result01 = decimal1.add(decimal2); System.out.println(result01);// 0.10 //相减运算 subtract() BigDecimal result02 = decimal1.subtract(decimal2); System.out.println(result02);// 0.08 //相减运算 multiply() BigDecimal result03 = decimal1.multiply(decimal2); System.out.println(result03);// 0.0009 //相减运算 divide() BigDecimal result04 = decimal1.divide(decimal2); System.out.println(result04);// 9
    复制代码

    BigInteger类:

    复制代码
    //加,减,乘,除   四则运算
            BigInteger bigInteger = new BigInteger("13213514541646225541");
            BigInteger bigInteger1 = new BigInteger("12312312312313212312");
            //相加运算
            BigInteger result1 = bigInteger.add(bigInteger1);
            System.out.println(result1);//25525826853959437853
            //减法运算
            BigInteger result2 = bigInteger.subtract(bigInteger1);
            System.out.println(result2);//901202229333013229
            //乘法运算
            BigInteger result3 = bigInteger.multiply(bigInteger1);
            System.out.println(result3);
            //除法运算
            BigInteger result4 = bigInteger.divide(bigInteger1);
            System.out.println(result4);
  • 相关阅读:
    bzoj3295
    bzoj1135
    [luoguP1328] 生活大爆炸版石头剪刀布(模拟)
    考后总结
    [luoguP1970] 花匠(DP)
    [POJ3463] Sightseeing(次短路 Heap + Dijkstra)
    [luoguP2885] [USACO07NOV]电话线Telephone Wire(DP + 贪心)
    [luoguP2709] 小B的询问(莫队)
    [luoguP1972] [SDOI2009]HH的项链(莫队 || 树状数组 || 主席树)
    [luoguP2617] Dynamic Ranking(树状数组 套 主席树 + 离散化)
  • 原文地址:https://www.cnblogs.com/rosiness/p/13951325.html
Copyright © 2011-2022 走看看