How to round integer in java

后端 未结 12 864
野趣味
野趣味 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:40

    You could try:

    int y = 1732;
    int x = y - y % 10;
    

    The result will be 1730.

    Edit: This doesn't answer the question. It simply removes part of the number but doesn't "round to the nearest".

提交回复
热议问题