Rounding to nearest 100

前端 未结 7 822

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:00

    Ruby's round method can consume negative precisions:

    n.round(-2)

    In this case -2 gets you rounding to the nearest hundred.

提交回复
热议问题