c#Numericupdown将值传递给整数 [英] c# Numericupdown to pass a value to an integer
问题描述
大家好,我在将numericupdown值传递给整数时遇到问题.
Good day everyone, I'm having a problem passing a numericupdown value into an interger.
private void button5_Click(object sender, EventArgs e)
{
int count = numericUpDown1.Value;
updateCount(count);
}
所以,我要这样做,就是将numericupdown值的值传递给名为count的整数,然后将其传递给更新数据库中表的方法.
So, what I want to do it so pass the value of the numericupdown value into integer named count and then pass the value into a method that updates a table in my database.
我最近才刚开始使用C#,似乎无法理解一些文档.
I just started c# lately and cant seem to understand some some documentation.
谢谢你们!
推荐答案
NumericUpDown.Value returns decimal so you need to round and convert to integer
使用此
int count = Convert.ToInt32(Math.Round(numericUpDown1.Value, 0));
updateCount(count);
如果将Increment
设置为整数(无小数点),则可以直接转换为整数类型,否则在转换之前先四舍五入是很安全的.
You can convert directly to the integer type if you have set Increment
to integer (no decimal points) number, otherwise it is safe to round first before conversion.
所以没有回合
int count = Convert.ToInt32(numericUpDown1.Value);
updateCount(count);
这篇关于c#Numericupdown将值传递给整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!