如何向下舍入到最接近的 X 数字 - VBScript 的伪代码
我正在尝试将数字向下舍入到最接近的 15、20、30。即
726 到最接近的 30 是 700
714 到最接近的 15 是 700 等等
VBScript 代码会非常有帮助,但伪代码也会有很大的帮助!
编辑:抱歉,我忘了说,726实际上是一个用int表示的时间,即07:26。所以这应该是 07:00,而不是 690
再次编辑:我只是提取分钟并使用人们回答的代码。希望这对其他人也有帮助。谢谢!
谢谢
I'm trying to round down a number to the nearest say 15, 20, 30. ie
726 to the nearest 30 is 700
714 to the nearest 15 is 700
etc
VBScript code would be very helpful but pseudocode would also be a huge help!
EDIT: Sorry, I forgot to say, that 726 is really a time expressed as an int, ie 07:26. So this should be 07:00, not 690
EDIT Again: I'm just extracting the minute and using the code people have answered with. Hopefully this will help someone else too. Thanks!
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
伪代码:
所以 726 mod 30 = 6
726 - 6 = 720
vbscript:
Pseudo code:
So 726 mod 30 = 6
726 - 6 = 720
vbscript:
您在标签中列出了多种语言。我将使用 C#,但是更通用的算法:
You listed a bunch of languages in your tags. I'm going with C#, but a more generic algorithm:
另一种方法是使用整数除法:726 / 30 * 30 = 720
another way to do it is just to use integer division: 726 / 30 * 30 = 720