四舍五入到最接近的100 [英] Rounding to nearest 100

查看:151
本文介绍了四舍五入到最接近的100的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

第一个数字需要被四舍五入到最接近的第二个数字。这样做有很多方法,但最新最好的和最短的算法?任何人都为一个挑战:-)

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

1244-> 1200
1254-> 1300
123-> 100
178-> 200
1576-> 1600
1449-> 1400
123456-> 123500
654321-> 654300
23-> 00
83-> 100

1244->1200
1254->1300
123->100
178->200
1576->1600
1449->1400
123456->123500
654321->654300
23->00
83->100

推荐答案

对于输入 N

(n + 50) / 100 * 100

使用整数除法。

using integer division.

请注意,很多语言/库已经具备的功能来做到这一点。

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

这篇关于四舍五入到最接近的100的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆