Java rounding up to an int using Math.ceil

前端 未结 15 1701
陌清茗
陌清茗 2020-11-29 17:42
int total = (int) Math.ceil(157/32);

Why does it still return 4? 157/32 = 4.90625, I need to round up, I\'ve looked around and this se

15条回答
  •  醉酒成梦
    2020-11-29 18:37

    Check the solution below for your question:

    int total = (int) Math.ceil(157/32);
    

    Here you should multiply Numerator with 1.0, then it will give your answer.

    int total = (int) Math.ceil(157*1.0/32);
    

提交回复
热议问题