我分2个整数,并希望得到一个整数。我想要正确的Math.Round()
方法,所以当我划分时,无论如何,它总是四舍五入到下一个整数。以下是一些预期如下的例子。什么是正整数分解为整数的正确方法?
int result = (6/4); // = 2
int result = (3/4); // = 1
int result = (1/4); // = 1
int result = (8/4); // = 2
int result = (9/4); // = 3
这样做的正确方法是什么?
问:你在乎负值?例如,在'-9d/4d'上使用'Math.Ceiling'会给你'-2'而不是'-3'。 – 2013-02-26 22:44:00