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

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

    I'm using this:

    public static int roundDoubleToUpperInt(double d){
        return (d%1==0.0f)?(int)d:(int)(d+1);
    }
    

提交回复
热议问题