Re: rounding a number



In article <EPGah.112081$Fi1.29936@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
*** Hendrickson <***.hendrickson@xxxxxxx> wrote:
arman wrote:
Hi,
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 fiddle around with the mod and modulus function. But, an
easier way Is to just do an integer divide.
J = K/10*10 + 10
will do what you want/ The divide throws away the remainder, the
multiply brings you back to a multiple of 10 that is smaller than you
want and the + 10 rounds up.

If you want to be careful about rounding values that are a multiple of
10, you could experiment with
J = (K+9)/10*10

I don't know whether Arman is really dealing with y-axis integers, or
with real variables that happen in his examples to have integer values.
If J and K above are real not integer then Arman won't get the benefit
of integer division above, and should replace K by NINT(K) or INT(K)
in experiments with ***'s two suggestions before deciding which of the
four possibilities to implement.

-- John Harper, School of Mathematics, Statistics and Computer Science,
Victoria University, PO Box 600, Wellington 6140, New Zealand
e-mail john.harper@xxxxxxxxx phone (+64)(4)463 5341 fax (+64)(4)463 5045
.


Quantcast