Round to nearest ones place value ex ante
1 view (last 30 days)
Please excuse me if this as been addressed/answered in a previous post, but I have not found a solution to this in my searches.
I am trying to round a number to certain ones place values that are unknown ex ante.
For example, the following value is unkown at first:
Now, once that number is known, I would like to know if the random number is closer to 3700 or 3705. In addition, the values of 3700 and 3705 are unkown at first as well.
Seems simple, but I'm struggling with this one, so any help is much appreciated!
Eric Delgado on 29 Sep 2022
Lim_down = 3700;
Lim_up = 3706;
x = randi([Lim_down Lim_up])
Lim_center = mean([Lim_down, Lim_up]);
if x < Lim_center; fprintf("Closer to %.0f", Lim_down);
elseif x > Lim_center; fprintf("Closer to %.0f", Lim_up);
else; fprintf("In between...");