Re: rounding a number



arman <previah@xxxxxxxxx> wrote:

How do you round some arbitrary number to the 10 multiplier? I need to
make a graph. The y-axis is dependent on the result of the computation.
If the maximum value of the y-axis, say for example 278, then I want
the y-axis to have a maximum of 300, or if it 2435 then I want the
maximum of 2500. So, basically it has to convert an arbitrary number
into some integer number that can be divided by 10.

You can start with rounding log10(), and then a loop to find
the appropriate multiple. Some allow multiplies of only 2 and 5,
others allow 2, 4, 5, 8, and possibly 3. (If plotting on
10 line per inch graph paper, 2 and 5 are best.)

Good axis label calculation isn't easy, especially if you allow
for graphs with the left or bottom coordinate non-zero.
Ones I knew did something like subtract the lower value from
the upper value, divide by the axis length, then take log10()
and round down. Next loop over the possible multipliers like
2, 4, 5, 8, 10, to see which one works.

Next, correct for the possibility that with the just determined
scale factor, the origin might not be on a grid line, requiring
recomputing the multiplier. Round the lower bound down and
the upper bound up to the appropriate multiple of as determined,
and test that the length is still right. If not, change the
multiplier and recompute the limits.

-- glen
.



Relevant Pages

  • Re: rounding a number
    ... Yes the y-axis is real. ... give unclear graphs if the maximum value of the graph 1.1 for example. ... easier way Is to just do an integer divide. ... multiply brings you back to a multiple of 10 that is smaller than you ...
    (comp.lang.fortran)
  • Re: rounding a number
    ... How do you round some arbitrary number to the 10 multiplier? ... The y-axis is dependent on the result of the computation. ... easier way Is to just do an integer divide. ... multiply brings you back to a multiple of 10 that is smaller than you ...
    (comp.lang.fortran)
  • Re: Court authorized wiretaps in the U.S. surged last year
    ... >> Draw a graph. ... Y-axis is how much harm is done to the users of those drugs. ...
    (sci.electronics.design)
  • Re: MSGraph Bars not drawing in right proportion
    ... I had already cleared the walls and Y-axis, so there was no y-axis to click ... It IS available for sametype of graph in Excel chart options, ... not bar - Chart Type ... there is specific Scale tab available for Y-axis in Column ...
    (microsoft.public.access.reports)
  • Re: rounding a number
    ... make a graph. ... The y-axis is dependent on the result of the ... goto 123 ... !finding axis location (location of first grid line) ...
    (comp.lang.fortran)