package retestC9;
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); //这里的r代表什么?后面r位置应该全是5,我把r改成5后为什么输出结果变了?
}
public static void main(String[] args) {
Test2 u=new Test2();
System.out.println(u.div(-7.5,-8.9,5,BigDecimal.ROUND_CEILING)); //为什么这里b小于零却没有输出提示信息?
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));
}
}
************
0.84270
-0.84269
-0.84270
-0.84270
-0.84270
-0.84270
-0.84270
|
|