用Math.Round获取一个可被5整除的数字 [英] Getting a number divisible by five with Math.Round
本文介绍了用Math.Round获取一个可被5整除的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个介于0到100之间的数字变量.它可能类似于83.333334.
I have a number variable that is between 0 and 100. It ccould be something like 83.333334.
我想使用 Math.Round
舍入数字(例如 Math.round(83.333334);
).我该怎么做才能使结果始终被5整除(即在[0,5,10,15 ... 85,90,95,100]中)?
I want to use Math.Round
to round the number (e.g. Math.round(83.333334);
). How can I do this so that the result is always divisible by five (i.e. in the set [0, 5, 10, 15... 85, 90, 95, 100])?
推荐答案
除以5,将其四舍五入,再乘以5.
Divide by 5, round it, multiply by 5.
alert(Math.round(83 / 5) * 5);
这篇关于用Math.Round获取一个可被5整除的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文