下一个最近的数字可被X整除 [英] Next Nearest Number Divisible By X
本文介绍了下一个最近的数字可被X整除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想做的基本上是取用户输入的任何数字,然后将其四舍五入为X可以除的下一个最接近的整数,不包括1.
What I want to do essentially, is take any number a user has input, and round it to the next closest whole number divisible by X, excluding 1.
IE(X = 300):
IE (X = 300):
输入= 1输出= 300
Input = 1 Output = 300
输入= 500输出= 600
Input = 500 Output = 600
输入= 841输出= 900
Input = 841 Output = 900
输入= 305输出= 300
Input = 305 Output = 300
推荐答案
(整数)除以X,加一,然后乘以X.
Just (integer) divide by X, add one, then multiply by X.
int output = ((input / x) + 1) * x;
这篇关于下一个最近的数字可被X整除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文