0
点赞
收藏
分享

微信扫一扫

java-BigInteger和BigDecimal

有点d伤 2022-02-14 阅读 75
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);



}
}
举报

相关推荐

0 条评论