Hey all,

I am trying to use a numeric up down object. But the problem is that I need the output to be an int since I need to feed the value as an argument for an int.

Example:

public void ExampleMethod(int lala) {
//stuff
}

ExampleMethod(numericUpDown1.Value);

By the way, numeric up down by default is decimal, and when I try to use Int32.Parse(); on it it doesn't work.

Convert the value to integer, and you should have the correct value, like:

private void numericUpDown1_ValueChanged(object sender, EventArgs e)
        {
            int value = Convert.ToInt32(this.numericUpDown1.Value);
        }

Convert the value to integer, and you should have the correct value, like:

private void numericUpDown1_ValueChanged(object sender, EventArgs e)
        {
            int value = Convert.ToInt32(this.numericUpDown1.Value);
        }

I guess Int32.Parse must have been the wrong method :D

Thanks!

I guess.Int32.Parse will do it too... but you have to assign the numericUpDown value to string, this is becuase value of numericUpDown`s control is in general a decimal vlaue. So parsing to string is needed.

So you have to do:

//to get the directly the value from numewric, you have to create decimal variable:
decimal aa = numericUpDown1.Value;
int bb = int.Parse(numericUpDown1.Value.ToString());
//and as said:
int cc = Convert.ToInt32(numericUpDown1.Value);

Hope it helps,
Mitja

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.