標題:
[發問]
HALF_DOWN和HALF_UP的差別?
[打印本頁]
作者:
t0129020
時間:
2020-1-19 17:08
標題:
HALF_DOWN和HALF_UP的差別?
程式碼如下:
package _03.bigdecimal;
import java.math.BigDecimal;
import java.math.RoundingMode;
public class BigDecimalDemo {
public static void main(String[] args) {
BigDecimal bd2=BigDecimal.valueOf(11);
BigDecimal bd3=new BigDecimal("2.3");
BigDecimal bdDiv = bd2.divide(bd3,38,RoundingMode.HALF_UP);
System.out.println(bdDiv);
BigDecimal bdDivDOWN = bd2.divide(bd3,10, RoundingMode.HALF_DOWN);
System.out.println(bdDivDOWN);
BigDecimal bdDivUP = bd2.divide(bd3,10, RoundingMode.HALF_UP);
System.out.println(bdDivUP);
}
}
編譯結果如下:
4.78260869565217391304347826086956521739
4.7826086957
4.7826086957
請問bdDivDOWN 為什麼和bdDivUP 的答案相同?
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)