# Thread: Scale back size of Numbers while maintaining proportion

1. ## Scale back size of Numbers while maintaining proportion

Hi,

I am been given a list of numbers in a certain format [19700, 19900, 79400, 79600, 79800, 179300, 179500, 279799 etc]. There is no maximum value on this list.

I need to scale back these numbers so that they don't exceed the number 5100 but I need to preserve the proportion of the numbers i.e. 179500 is higher than 79600 which is higher than 79400 etc etc.

I thought I could do this with mod 5100 but in hindsight that doesn't work...

Any suggestions would be greatly appreciated about how I should approach this.

2. Maybe divide by a common no.?
...but that would(for whole no.s) convert some > or < conditions to >= and <= resp.

3. Do you mean that some of the numbers could end up the same? I need them to be unique......

Is there any way to approach this using mod combined with something else?

4. Actually from doing some more searching I think there's no way to do this unless I know the highest number in my list (279799 in the list I gave above). If I know this I can scale it according to the below:

r = 5100 * (value / Integer_MAX_VALUE)

e.g. r = 5100 * (79600/279799)

5. Actually from doing some more searching I think there's no way to do this unless I know the highest number in my list
You could find it at runtime....if the lists are not too large to do that nicely.

Though it doesn't sound like a good idea, I think you could wing it by storing it as a double (if that isn't accurate enough/...use some Arbitrary Precision library....and the associated power of 10 to get back the original number)

6. Originally Posted by kerrymaid
e.g. r = 5100 * (79600/279799)
Not quite... That would result in zero because you are using integer division there. You would need to do r = 5100 * 79600 / 279799 and let the multiplication happen first. However you will have to be careful to avoid integer overflow. If you get overflow then use a 64-bit data type (fixed or floating).

Of course none of this prevents the scaling from mapping two input values to the same output value, so according to the below statement, you appear to be screwed:
Do you mean that some of the numbers could end up the same? I need them to be unique......

Popular pages Recent additions