http://www.verejava.com/?id=17159675312132
import java.math.BigDecimal;
import java.math.BigInteger;
public class Test {
public static void main(String[] args) {
// 计算 1 到 30 的相乘的结果
BigInteger sum = new BigInteger("1");
for (int i = 1; i <= 30; i++) {
sum = sum.multiply(new BigInteger(String.valueOf(i)));
}
System.out.println(sum);
BigInteger bi1 = new BigInteger("20000000002000000002");
BigInteger bi2 = new BigInteger("40000000004000000004");
System.out.println(bi1.add(bi2));
System.out.println(bi2.subtract(bi1));
System.out.println(bi1.divide(new BigInteger("2")));
BigDecimal bd1 = new BigDecimal("20000000002000000000.0000000002");
BigDecimal bd2 = new BigDecimal("30000000003000000000.0000000003");
System.out.println(bd1.add(bd2));
System.out.println(bd2.subtract(bd1));
System.out.println(bd2.divide(new BigDecimal("2")));
System.out.println(bd2.multiply(new BigDecimal("2")));
}
}