round a floating-point number to the next integer value in java

后端 未结 6 1350
广开言路
广开言路 2020-12-29 18:08

how can i round up a floating point number to the next integer value in Java? Suppose

2.1 -->3

3.001 -->4

4.5 -

6条回答
  •  自闭症患者
    2020-12-29 18:48

    If it helps someone, here's how I get this working:

    int arraySize = 3;
    int pageSize = 10;
    int pagesQty = (int) Math.ceil(arraySize / (float) pageSize);
    
    System.out.println(pagesQty);
    
    //Displays 1
    

    Divisor must be a float in order to work properly.

提交回复
热议问题