我分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