Re: rounding a number



Adding my 2-cents, I generally want to come up with a min, max and step (for
labels or gridlines)
I make the min and max multiples of the step, and pick the step so that the
number of steps falls within
a specified range, usually between 10 and 20. For integers, I like to use
steps like 1,2,5,10,20,25,50,

Another thing to consider is whether your scale should simply match the data
or whether it should be extended
to a more "natrural" range. For example, I do a lot of plots involving
reservoir information which includes
headwater elevations and dam releases. For the releases, we generally want
the scale to start at 0 regardless
of whether the data happens to include a 0. For the elevations, we will
often have a default scale setting
that includes the normal range of data, and only override the scale the data
to be plotted falls outside the normal
range. If you make a big pile of plots and want to compare them to each
other, its generally a lot easier if
they all are drawn with the same scale.

"glen herrmannsfeldt" <gah@xxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:ekfg4d$f8q$1@xxxxxxxxxxxxxxxxxxx
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: Modularity problems with multiple dispatch
    ... It doesn't scale because there is no good way to select an f ... doesn't scale in the sense that you cannot simply dispatch on all ... which in turn means that *then* you wouldn't even care about multiple ... generics is that you can extend it everywhere so if fis ...
    (comp.lang.functional)
  • Re: Excel should allow multiple X and Y scales for...
    ... Jon Peltier, Microsoft Excel MVP ... > series have widely varied ranges, and I need multiple X-scales, stacked on ... > reverse order) and the other parameters are on the X-axis. ... > scale. ...
    (microsoft.public.excel.charting)
  • Re: Modularity problems with multiple dispatch
    ... What do you mean by "too many problems" and "doesn't scale to multiple ... (no break of encapsulation) ... instance members can only be accessed within methods of the class ...
    (comp.lang.functional)
  • RE: 2 columns Report with multiple records
    ... My Client is using Every 3x4 Labels for this report. ... Does Column in the Report support multiple records ... "Duane Hookom" wrote: ...
    (microsoft.public.access.reports)
  • Re: Restructure this!
    ... Horrible code can be produced using any statement or any language. ... it is the use of labels in ... multiple ways that cause 'nightmares'. ... It isn't verbs that produce bad code, ...
    (comp.lang.cobol)