BigInteger和BigDecimal
Biglnteger
适合保存比较大的整型
BiaDecima
l活合保存精度更高的浮点型小数)
一、BigInteger的常用方法
add
加
subtract
减
multiply
乘
divide
乘
package com.hspedu.bignum_;
import java.math.BigInteger;
public class BigInteger_ {
public static void main(String[] args) {
long l = 2345646546911L;
System.out.println("L=" + l);
BigInteger bigInteger = new BigInteger("23");
BigInteger bigInteger2 = new BigInteger("10");
System.out.println(bigInteger);
BigInteger add = bigInteger.add(bigInteger2);
System.out.println(add);
BigInteger subtract = bigInteger.subtract(bigInteger2);
System.out.println(subtract);
BigInteger multiply = bigInteger.multiply(bigInteger2);
System.out.println(multiply);
BigInteger divide = bigInteger.divide(bigInteger2);
System.out.println(divide);
}
}
二、BigDecimal的常用方法
add
加
subtract
减
multiply
乘
divide
乘
package com.hspedu.bignum_;
import java.math.BigDecimal;
public class BigDecimal_ {
public static void main(String[] args) {
BigDecimal bigDecimal = new BigDecimal("1999.111111999999999999999999999");
BigDecimal bigDecimal1 = new BigDecimal("1.1");
System.out.println(bigDecimal);
BigDecimal add = bigDecimal.add(bigDecimal1);
System.out.println(add);
BigDecimal subtract = bigDecimal.subtract(bigDecimal1);
System.out.println(subtract);
System.out.println(bigDecimal.multiply(bigDecimal1));
System.out.println(bigDecimal.divide(bigDecimal1,BigDecimal.ROUND_CEILING));
}
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!