Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have 5- 10 nos of textboxes on the form with some values..
and a numericUpDown control..
i have to add precision to textbox values according to numericupdown control..
for eg.
if numericupdown control value is 1 then textbox value should be like 105.0
or if numericupdown control value is 2 then textbox value should be like 105.00

this would happen at runtime, when i change the value of numericUpDown control value of textbox also change with precision...
thnxxxx
Posted

Use the String::Format()[^] method with the appropriate precision settings.
 
Share this answer
 
C#
private void NumericUpDown1_ValueChanged(Object sender, EventArgs e)
{
    int numberOfDecimals = (int)yourNumericUpDown.Value;
    yourTextBox.Text = yourValue.ToSring("F" + numberOfDecimals.ToString());
}
 
Share this answer
 
C#
private void NumericUpDown1_ValueChanged(Object sender, EventArgs e)
{
    int numberOfDecimals = (int)yourNumericUpDown.Value;
    yourTextBox.Text = yourValue.ToSring("F" + numberOfDecimals.ToString());
}


thnx for ur solution
But I have to add precision to all textboxes at the same time....
 
Share this answer
 
Then you probably want something like that:

private void NumericUpDown1_ValueChanged(Object sender, EventArgs e)
{
    UpdateTextBoxes();
}
//you can call this from anywhere at anytime to update every text boxes
public void UpdateTextBoxes()
{
    int numberOfDecimals = (int)yourNumericUpDown.Value;
    string formatString = "F" + numberOfDecimals.ToString();
    textBox1.Text = yourValue1.ToSring(formatString);
    textBox2.Text = yourValue2.ToSring(formatString);
    textBox3.Text = yourValue3.ToSring(formatString);
    //... do as many as you want
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900