• java高精度实数和小数


    java 高精度实数和小数

            String s = "1231222222222222222222222222222222222222222222222222222222";
            BigInteger a = new BigInteger(s);
            System.out.println(a.toString());
            String s1 = "1.2222222222222222311111111122222222222222222222222222222";
            BigDecimal a1 = new BigDecimal(s1);
            System.out.println(a1.toString());
    

      

    Ⅰ基本函数:

    1.valueOf(parament); 将参数转换为制定的类型

       比如 int a=3;

           BigInteger b=BigInteger.valueOf(a);

         b=3;

             String s=”12345”;

           BigInteger c=BigInteger.valueOf(s);

           c=12345;

    2.add(); 大整数相加

       BigInteger a=new BigInteger(“23”);

       BigInteger b=new BigInteger(“34”);

    a.      add(b);

    3.subtract(); 相减

    4.multiply(); 相乘

    5.divide();    相除取整

    6.remainder(); 取余

    7.pow();   a.pow(b)=a^b

    8.gcd();   最大公约数

    9.abs(); 绝对值

    10.negate(); 取反数

    11.mod(); a.mod(b)=a%b=a.remainder(b);

    12.max(); min();

    13.punlic int comareTo();

    14.boolean equals(); 是否相等

    15.BigInteger构造函数:

       一般用到以下两种:

       BigInteger(String val);

    将指定字符串转换为十进制表示形式;

       BigInteger(String val,int radix);

    将指定基数的 BigInteger 的字符串表示形式转换为 BigInteger

    Ⅱ.基本常量:

       A=BigInteger.ONE    1

    B=BigInteger.TEN    10

    C=BigInteger.ZERO   0

    Ⅲ.基本操作

    1.   读入:

    用Scanner类定义对象进行控制台读入,Scanner类在java.util.*包中

    Scanner cin=new Scanner(System.in);// 读入

    while(cin.hasNext())   //等同于!=EOF

    {

       int n;

       BigInteger m;

       n=cin.nextInt(); //读入一个int;

       m=cin.BigInteger();//读入一个BigInteger;

    System.out.print(m.toString());

    }

    http://blog.csdn.net/major_zhang/article/details/54668470

  • 相关阅读:
    让网络编程更轻松和有趣 t-io
    设计一个百万级的消息推送系统
    前端安全系列之二:如何防止CSRF攻击
    Maven仓库下载jar包失败的处理方案
    SpringBoot2中配置文件的调整,升级SpringBoot2时候注意的坑
    Table折叠小技巧html-demo
    mysql如何分类统计数量
    前台登录和Token信息交互流程
    windows下安装mysql5.6
    【读书笔记】-- 你不知道的JavaScript
  • 原文地址:https://www.cnblogs.com/smuxiaolei/p/7744258.html
Copyright © 2020-2023  润新知