How to round integer in java

后端 未结 12 855
野趣味
野趣味 2020-12-09 09:19

I want to round the number 1732 to the nearest ten, hundred and thousand. I tried with Math round functions, but it was written only for float and double. How to do this for

12条回答
  •  情话喂你
    2020-12-09 09:27

    I usually do it this way:

    int num = 1732;
    int roundedNum = Math.round((num + 9)/10 * 10);
    

    This will give you 1740 as the result.

    Hope this will help.

提交回复
热议问题