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

后端 未结 6 1382
广开言路
广开言路 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

    See

    float a=10.34f,b=45.678f;
    
    System.out.println((int)Math.ceil(a));
    System.out.println((int)Math.ceil(b));
    

    Output

    11
    46
    

提交回复
热议问题