× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Booth Martin wrote on 18/08/2007 13:42:48:

I am printing a 13-month graph of values. I can find the highest value,

which might range from tens to millions. The graph's vertical scale
will have 5 values. I plan to reduce the top scale number to be less
than 100,000. But I want it to be an even value that is a larger value
than the highest of the 13 values I am graphing. Since I want to deal
with whole numbers on the graph, my target is to calculate the lowest
number, then multiply it by 2, 3, 4, & 5 to get the other values.

For instance I am thinking that it might be something like this:

Highest value First scale value
123 25
1234 250
12345 2500
123456 25 (x000)
1234567 250 (x000)
12345678 2500 (x000)

This is kind of a long answer, so here's the executive summary:
I think you need three procedures. One will find the number of digits in
a given integer, one will take a number and round it to next highest
multiple of a some other number, and another will determine what number
you should round to in order to have 'nice' values for your scale.

The reasoning:
It looks to me like two separate problems.

1. How to determine the highest number on the scale for numbers less than
100 000?

Essentially, it seems your goal is to round to the next highest X. So, if
X=25, then result values would be 0,25,50,etc. The algorithm is as
follows (with i = input value):

y = i mod X
if ( y = 0 )
return i
else
return i - y + X


So the now the problem is how to determine what X should be for a
particular highest value. What are acceptable values for the scale
markers? Is your goal to have as little "wasted" space at the top of the
graph as possible, or to ensure that the scale values are "pretty" (that
is, multiples of 5 or something like that)?

I expect that you want your scale values to be integers, so X should be a
multiple of 5. So, to minimize wasted space you could choose X = 5 no
matter what the highest value is. If your goal is prettiness, then it
gets more complicated. I think a good way would be to use the formula X
=Y / 4, where Y = (10^(number of digits - 1)). The -1 is because 1000 is
10^3, not 10^4.


2. How to map values greater than 100 000 into the range [0,100 000]?
For the second problem, I guess the simplest solution would be to drop
enough of the least significant digits so that the highest value will fit
in the range. So, (10, 100, 1000, 123456, 12345678, 10000, 50000) => (0,
0, 1, 123, 12345, 10, 50).


In both problems 1 and 2, as well as using Antonio's algorithm, the tricky
bit is how to efficiently find the number of digits in a given number. I
can think of two ways to do this in RPG:

a) Divide by successive powers of 10 until the result is less than 1. The
number of times you need to divide is the number of digits. This is a
good candidate for a recursive procedure:
numberOfDigits (input)
if ( (input / 10) < 1 )
return 1
else
return numberOfDigits(input/10) + 1
endif
endproc

b) numberOfDigits = %len(%trimR(%char( input )))


HTH,
Adam


P.S. - can you tell I'm a math nerd?

Attention:

The information contained in this message and or attachments is
intended only for the person or entity to which it is addressed and may contain
confidential and/or privileged material. Any review, retransmission,
dissemination or other use of, or taking of any action in reliance upon, this
information by persons or entities other than the intended recipient is
prohibited. If you received this message in error, please contact the sender and
delete the material from any system and destroy any copies. Thank you for your
time and consideration.

Attention:

Le contenu de ce message et(ou) les fichiers ci-joints s?adressent
exclusivement à la personne ou -entité à laquelle ils sont destinés. Ils peuvent
contenir de l?information confidentielle, protégée et(ou) classifiée. Il est
strictement interdit à toute personne ou entité autre que le(la) destinataire
prévu(e) de ce message d?examiner, de réviser, de retransmettre ou de diffuser
cette information, de prendre une quelconque action en fonction ou sur la base
de celle-ci, ou d?en faire tout autre usage. Si vous avez reçu ce message par
erreur, veuillez communiquer avec l?expéditeur(trice), supprimer ce message et
les fichiers ci-inclus de tout système, et en détruire toutes copies, qu?elles
soient électroniques ou imprimées. Nous vous remercions de votre entière
collaboration.

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.