当前位置:首页 > IT技术 > 编程语言 > 正文

java-BigInteger和BigDecimal
2022-02-14 14:06:21

package Bigdate;

import java.math.BigInteger;

/**
* @author jee
* @version 1.0
*/
public class Bigdata {
public static void main(String[] args) {
// BigInteger和BigDecimal
// 1.BigInteger适合保存比较大的整数
// 2.BigDecimal适合保存比较大的小数
//
BigInteger bigInteger = new BigInteger("54546559448948999999999999999999999999999999999999999999");
// 在BigInteger与BigDecimal进行加减乘除时,需要使用对应的方法,不能直接使用+ - * /
// 1.加
BigInteger add = bigInteger.add(bigInteger);
System.out.println(add);

// 2.减
BigInteger subtract = bigInteger.subtract(bigInteger);
System.out.println(subtract);

// 3.乘
BigInteger multiply = bigInteger.multiply(bigInteger);
System.out.println(multiply);

// 4.除
BigInteger divide = bigInteger.divide(bigInteger);
System.out.println(divide);



}
}

本文摘自 :https://blog.51cto.com/u