我通過使用計時器並將它們添加到列表框或datagridview中獲取數據。我需要得到每個數十年的價值,例如; 10,20,30,40,50..
如何在c#中獲得每十年最接近的價值?
但並不總是數據來自我想要的。有一個示例數據來了; 10.15 14.45 19.65 22.18 27.89 30.15 31.15 37.46 42.01 ...
根據上面的數據,我想列出這些數據在我的代碼;
10.15 as 10 19.65 as 20 30.15 as 30 42.01 as 40 ...
正如你看到的,我不想錯過任何的十年。 在我的代碼label1.text represents velocity
,label2.Text represents time
和watch is a stopwatch
首先,我正在收集數據給lisboxes,然後將它們帶到datagirview.Here是我的代碼;
private void timer2_Tick(object sender, EventArgs e)
{
watch.Start();
var time = watch.Elapsed.TotalSeconds;
if (Math.Round(Convert.ToDouble(label1.Text)) % 10 == 0)
{
listBoxTime.Items.Add(label2.Text);
listBoxVelocity.Items.Add(label1.Text);
p = dataGridView1.Rows.Add();
for (int i = 1; i < listBoxTime.Items.Count; i++)
{
dataGridView1.Rows[p].Cells[0].Value = listBoxVelocity.Items[i].ToString();
dataGridView1.Rows[p].Cells[1].Value = listBoxTime.Items[i].ToString();
}
}
}
正如我之前所說,我應該怎麼做才能獲得每個十年最接近的數據而不會錯過任何十年。
我預計10.5,因爲它比11.5更接近10。 – Quanthema
你期望15回合到什麼程度? 25呢? – mjwills
會發生這種情況有十年沒有了嗎? – Ecstabis