我在将一个数字向下的值传递到一个整数时遇到了问题。
private void button5_Click(object sender, EventArgs e)
{
int count = numericUpDown1.Value;
updateCount(count);
}因此,我想要做的是将数值的值传递给一个名为count的整数,然后将该值传递到一个更新数据库中的表的方法中。
我最近刚开始编写C#程序,似乎无法理解一些文档。
发布于 2015-08-26 01:46:43
NumericUpDown.Value返回十进制,所以您需要舍入并转换为整数。
用这个,
int count = Convert.ToInt32(Math.Round(numericUpDown1.Value, 0));
updateCount(count);如果您已将Increment设置为整数(无小数点)数字,则可以直接转换为整数类型,否则在转换之前先转一圈是安全的。
所以没有圆
int count = Convert.ToInt32(numericUpDown1.Value);
updateCount(count);https://stackoverflow.com/questions/32216708
复制相似问题