package practice;
import java.math.*;
public class Test2 {
/**
* @param args
*/
public static BigDecimal div(double value1,double value2,int b,int r){
if(b<0){
System.out.println("b值必须大于等于0");
}
BigDecimal b1=new BigDecimal(Double.toString(value1));
BigDecimal b2=new BigDecimal(Double.toString(value2));
return b1.divide(b2,b,r);
}
public static void main(String[] args) {
// TODO 自动生成方法存根
Test2 u=new Test2();
//System.out.println(u.div(-7.5,8.9,5,BigDecimal.ROUND_CEILING));
//System.out.println(u.div(-7.5,8.9,5,BigDecimal.ROUND_DOWN));
//System.out.println(u.div(-7.5,8.9,5,BigDecimal.ROUND_FLOOR));
//System.out.println(u.div(-7.5,8.9,5,BigDecimal.ROUND_HALF_DOWN));
//System.out.println(u.div(-7.5,8.9,5,BigDecimal.ROUND_HALF_EVEN));
System.out.println(u.div(-7.5,8.9,5,BigDecimal.ROUND_HALF_UP));
//System.out.println(u.div(-7.5,8.9,5,BigDecimal.ROUND_UP));
}
}
package practice;
import java.math.BigDecimal;
public class BigDecimalDemo {
public static void main(String[] args) {
System.out.println(bd(-7.5,8.9,5,BigDecimal.ROUND_HALF_UP));
}
public static BigDecimal bd(double num1,double num2,int c,int r){
BigDecimal a=new BigDecimal(Double.toString(num1));
BigDecimal b=new BigDecimal(Double.toString(num2));
return a.divide(b,c,r);
}
}
上面那个程序用new 初始化 下面的没有初始化 但是都出同样的答案,请问是为什么 区别在哪里
|
|