I need to know how to round to the nearest quarter and tenth.
Right now i am taking to times finding the difference and then trying to round to the nearest quarter or tenth. Which ever i choose.
I have this for code.
I made a class to call, In my class i have this.
namespace WindowsFormsApplication3
{
class Time
{
public Time(string a)
{
}
public string Times(string textBox1, string textBox2)
{
DateTime Time1 = DateTime.Parse(textBox1);
DateTime Time2 = DateTime.Parse(textBox2);
TimeSpan result = Time2 - Time1;
int Hours = result.Hours;
decimal Min = result.Minutes;
decimal decTime = Hours + (((Min * 100) / 60) / 100);
decTime = Math.Round(decTime, 2);
return decTime.ToString();
}
}
}
This is what is in the form itself.
private void radioButton3_CheckedChanged(object sender, EventArgs e)
{
if ((textBox6.Text != "") || (textBox7.Text != ""))
{
textBox19.Text = new Time("").Times(textBox6.Text, textBox7.Text);
decimal dec = Convert.ToDecimal(textBox19.Text);
dec = Math.Floor(dec);
dec = Math.Round(dec, 2);
dec = System.Decimal.Add(dec, 0.25m);
textBox19.Text = dec.ToString();
if (textBox10.Text != "")
{
decimal Min = Convert.ToDecimal(textBox10.Text);
dec = dec - convertToDec(Min);
textBox19.Text = dec.ToString();
}
}
else
{
MessageBox.Show("Must be a start/stop time");
}
}