Java rounding up to an int using Math.ceil

前端 未结 15 1703
陌清茗
陌清茗 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:22

    Also to convert a number from integer to real number you can add a dot:

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

    And the result of (157/32.) will be real too. ;)

提交回复
热议问题