Im using Visual Studio 2010, windows form (c#).
I need change decimals place of value in textbox using numericUpDown1.
example:





I tryed this code:
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
// tbxConvertito.Text = (decimal.Parse(tbxConvertito.Text) * 10m).ToString();
if (numericUpDown1.Value == 0)
{
int decimalPlace = 0;
// Decimal xDecimal = decimal.Parse(tbxConvertito.text);
decimal xDecimal = decimal.Parse(tbxConvertito.Text);
tbxConvertito.Text = (Math.Round(xDecimal, decimalPlace)).ToString();
}
if (numericUpDown1.Value == 1)
{
int decimalPlace = 1;
// Decimal xDecimal = decimal.Parse(tbxConvertito.text);
decimal xDecimal = decimal.Parse(tbxConvertito.Text);
tbxConvertito.Text = (Math.Round(xDecimal, decimalPlace)).ToString();
}
}
but not work. How can I solve this, please?
You should create field with decimal value, to keep original value.
If you do that:
You lose original value of your decimal variable.
Try this:
Solution without use
Roundmethod: