mardi 24 février 2015

C# - How can I convert the string value to decimal places?

Basically, ive created a form that I can select different shapes that when a value on the track bar is selected, works out both the area and boundary length of either a circle, triangle or square.


The values are currently coming through with a lot of decimal places and I want to set up radio buttons to choose whether 2, 3 or 4 decimal places.



private void sliderBar(object sender, EventArgs e)
{

textBox3.Text = trackBar1.Value.ToString();

if(circleButton.Checked == true)
{
textBox2.Text = (circle.getArea(trackBar1.Value)).ToString();
textBox1.Text = (circle.getBoundLength(trackBar1.Value)).ToString();
}
else if(squareButton.Checked == true)
{
textBox2.Text = (square.getArea(trackBar1.Value)).ToString();
textBox1.Text = (square.getBoundLength(trackBar1.Value)).ToString();
}
else
{
textBox2.Text = (triangle.getArea(trackBar1.Value)).ToString();
textBox1.Text = (triangle.getBoundLength(trackBar1.Value)).ToString();
}

if (decimalPlaces2Button.Checked == true)
{
TextBox2.Text = decimal.Round(textBox2, 2, MidpointRounding.AwayFromZero).ToDouble();

}
}

Aucun commentaire:

Enregistrer un commentaire