package com.wf.bean;
/*
* @BigInteger and BigDecimal
*/
import java.math.BigDecimal;
import java.math.BigInteger;
public class Demo8 {
public static void main(String[] args) {
// demo();
BigDecimal bd = new BigDecimal("2.0");
BigDecimal bd1 = new BigDecimal("1.9");
System.out.println(bd.add(bd1));
System.out.println(bd.subtract(bd1));
System.out.println(bd.multiply(bd1));
// System.out.println(bd.divide(bd1)); //抛出java.lang.ArithmeticException
BigDecimal[] bd2 = bd.divideAndRemainder(bd1);
for (int i = 0; i < bd2.length; i++) {
System.out.println(bd2[i]);
}
}
private static void demo() {
BigInteger bi = new BigInteger("100");
BigInteger bi1 = new BigInteger("20");
System.out.println(bi.add(bi1));
System.out.println(bi.subtract(bi1));
System.out.println(bi.multiply(bi1));
System.out.println(bi.divide(bi1));
BigInteger bi2 [] = bi.divideAndRemainder(bi1);
for (int i = 0; i < bi2.length; i++) {
System.out.println(bi2[i]);
}
}
}
|
|