S
S
Shayden2021-10-01 17:55:22
C++ / C#
Shayden, 2021-10-01 17:55:22

Outputting average double number in textBox?

There are two nums, namely:

double num1 = double.Parse(this.dataGridView1.Rows[acID].Cells[3].Value.ToString());
double num2 = double.Parse(this.textBox3.Text.ToString().Trim());


How can I make it so that when a dropout (no matter what number) is in the dataGridView1.Rows[acID].Cells[3] cell in the textBox3 field, the number specified there changes? Moreover, the essence here is this: Let's say in textBox3 initially I put the number "0.69". And in the dataGridView1.Rows[acID].Cells[3] cell, a number, for example, "9.34" fell out (and it goes there from 0.0 to 10.0 seconds, after that it counts again from zero). It is necessary to make sure that in textBox3 a new number is indicated, in the range: from the old number "0.69" to the one dropped in the cell "9.34".

It is a pity that this cannot be done with such code)) as:

Random z = new Random();
textBox3.Text = z.Next(num1, num2).ToString();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Glebov, 2021-10-07
@GLeBaTi

var gridNum = ...from grid
var rnd = new Random();
var prev = double.Parse(textBox3.Text);
var next = prev + ((gridNum - prev) * rnd.NextDouble());
textBox3.Text = next.ToString();

Something like this. This is assuming grid value >= textBox3 value

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question