zoukankan      html  css  js  c++  java
  • BigInteger和BigDecimal的基本用法

    整型大数 BigInteger:

    import java.math.BigInteger;
    import java.util.Scanner;
    public class Main {
           public static void main(String[] args) {
                 Scanner scan=new Scanner(System.in);
                 BigInteger a =new BigInteger("100");
                 BigInteger b= new BigInteger("25");
                 System.out.println(a.subtract(b)); //大整数的减
                 System.out.println(a.add(b));        //大整数的加
                 System.out.println(a.multiply(b));//大整数的乘
                 System.out.println(a.divide(b));    //大整数的除
                 System.out.println(a.remainder(b)); //大数取余

    //其他类型转换成大整数
       int aa=3;
    BigInteger b=BigInteger.valueOf(aa);
    System.out.println(b);
        }
    }

    浮点型大数 BigDecimal 加减乘除用法 同BigInteger

    BigDecimal中,如果除不尽,divide格式应该这样写:
    System.out.println(x.divide(y,3,BigDecimal.ROUND_HALF_UP));//分别代表的是除数,保留的位数,方式为四舍五入。
    BigDecimal a=new BigDecimal("1");
    BigDecimal b=new BigDecimal("3");
    System.out.println(a.divide(b,3,BigDecimal.ROUND_HALF_UP));
  • 相关阅读:
    继承
    面向对象_封装练习
    ajax分页与组合查询配合使用
    Linq的分页与组合查询的配合使用
    发送邮件和数据导出
    GridView的使用
    母版页的使用
    DIV+CSS命名规范
    Ajax基础
    jQuery动画效果
  • 原文地址:https://www.cnblogs.com/qdu-lkc/p/12189215.html
Copyright © 2011-2022 走看看