本文介绍了请帮帮我,解决这个C#5/2 = 2?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

{
加倍= 5/2;

up = Math.Ceiling(上);



双降= 5/2;

down = Math.Floor(下);



MessageBox.Show(up+ up +down + down);

}



''来自MessageBox的结果是向上2倒2

''我希望结果是up 3 down 2



我尝试过:



i尝试5/2或

a = 5/2

加倍= a;

up =数学.Ceiling(up);

{ double up = 5/2;
up = Math.Ceiling(up);

double down = 5/2;
down = Math.Floor(down);

MessageBox.Show("up " + up + " down " + down);
}

'' the result from MessageBox is " up 2 down 2"
'' i want the result is " up 3 down 2"

What I have tried:

i have try 5/2 or
a = 5 / 2
double up = a;
up = Math.Ceiling(up);

推荐答案


引用:

请帮助我,解决这个C#5/2 = 2?

Please help me, to solve this C# 5/2 = 2?



这里没有什么可解决的。 5/2是一个带整数结果的整数除法。

如果你想要一个浮点除法,试试:


There is nothing to solve here. 5/2 is an integer division with an integer result.
If you want a floating point division, try:

double up = 5/2.0;
// or
double up = 5.0/2;


int down= 5/2; // down=2
int mod = 5%2; // mod =1

int down= 6/2; // down=3
int mod = 6%2; // mod =0


这篇关于请帮帮我,解决这个C#5/2 = 2?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 21:29