Java: How do I perform integer division that rounds towards -Infinity rather than 0?

前端 未结 4 1530
轮回少年
轮回少年 2020-12-17 16:20

(note: not the same as this other question since the OP never explicitly specified rounding towards 0 or -Infinity)

JLS 15.17.2 says that integer di

4条回答
  •  一向
    一向 (楼主)
    2020-12-17 17:17

    return BigDecimal.valueOf(n).divide(BigDecimal.valueOf(d), RoundingMode.FLOOR).longValue();
    

提交回复
热议问题