1、Math类
Math类中的所有方法都为静态方法(工具方法),Math类叫做工具类,使用时查找API即可
@Test
public void test(){
System.out.println(Math.random());
System.out.println(Math.round(4.5));
System.out.println(Math.round(-4.5));
}
2、BigInteger类
大整数类型,比整数可以表达的范围大得多,一般用于大数据领域。不支持直接的加减乘除,需要通过方法实现数据的加减乘除。
@Test
public void test1(){
BigInteger bi = new BigInteger("2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222");
BigInteger bi2 = new BigInteger("333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333");
BigInteger multiply = bi.multiply(bi2);
System.out.println(multiply);
}
3、BigDecimal类
表示任意大的有理数,与double、float不同,BigDecimal要求数字尽可能的精确
@Test
public void test2(){
BigDecimal bd = new BigDecimal("33333333.33333333333333333333333333333333333333333333333333333");
BigDecimal bd2 = new BigDecimal("4444.444444444444444444444444444444444444444444444444444444444444444444444444444");
BigDecimal divide = bd2.divide(bd,10,BigDecimal.ROUND_DOWN);
System.out.println(divide);
}