标签:ati main stat multi method dem java divide strong
import java.math.BigDecimal;
import java.math.BigInteger;
public class Demo04 {
public static void main(String[] args) {
method1();
method2();
}
//比long还大的整形计算
public static void method1(){
BigInteger bin1=new BigInteger("1111111111111111111111111111111111111");
BigInteger bin2=new BigInteger("1111111222222222222211111111111111111");
//加法
System.out.println(bin1.add(bin2));
//减法
System.out.println(bin2.subtract(bin1));
//乘法
System.out.println(bin1.multiply(bin2));
//除法
System.out.println(bin2.divide(bin1));
}
//实现浮点数据的高精度运算
public static void method2(){
BigDecimal bd1=new BigDecimal("0.09");
BigDecimal bd2=new BigDecimal("0.01");
System.out.println(bd1.add(bd2));//0.10
System.out.println(bd1.multiply(bd2));//0.0009
System.out.println(bd1.divide(bd2,1,BigDecimal.ROUND_CEILING));//9.0
}
}
标签:ati main stat multi method dem java divide strong
原文地址:https://www.cnblogs.com/zhaotao11/p/10219056.html