Rounding to nearest 100

前端 未结 7 808

First number needs to be rounded to nearest second number. There are many ways of doing this, but whats the best and shortest algorithm? Anyone up for a challenge :-)

相关标签:
7条回答
  • 2020-12-15 05:11

    For input n:

    (n + 50) / 100 * 100
    

    using integer division.

    Note that many languages/libraries already have functions to do this.

    0 讨论(0)
提交回复
热议问题