本文介绍了非常基本划分公式不工作在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不能得到这个分成小数。这是四舍五入到0值。
私人无效button24_Click(对象发件人,EventArgs五)
{
双X = 0;
X = 1/2;
ans.Text = x.ToString();
}
当我调试,x是零,然后发送到文本框ANS 。
我tried..and字符串变量仍然是零。
双X = 1/5;
串displayX = x.ToString(0.0000); // EN:
解决方案
这是的,而这些都是预期的产出。
双X = 1.0 / 5; //这不会执行整数除法
双X = 1/5; //这样做(1/5 = 0)。
双X = 1D / 5; //这个不会因为1被视为双
I can't get this to divide into a decimal. It is rounding to value 0.
private void button24_Click(object sender, EventArgs e)
{
double x = 0;
x = 1 / 2;
ans.Text = x.ToString();
}
When I debug, x is zero before it is sent to the textbox 'ans.'
I tried..and string variable is still zero..
double x = 1/5;
string displayX = x.ToString("0.0000");
解决方案
It's integer division and those are the expected outputs.
double x = 1.0 / 5; // this will not perform integer division
double x = 1/5; // this does (1/5 = 0).
double x = 1D / 5; // this will not because 1 is treated as a double
这篇关于非常基本划分公式不工作在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!