rescale a range of numbers

  • Thread starter Thread starter Joe
  • Start date Start date
J

Joe

I have a range from say 26.43534 - 234.24 and a value of 118.12.

I need to change this range to 0 - 255 and find out where my value falls
within it (so the value also needs to be rescaled).

I thought there was a way to do this by adding 255 but I can't remember how.

Any suggestions?

-Joe
 
Joe said:
I have a range from say 26.43534 - 234.24 and a value of 118.12.

I need to change this range to 0 - 255 and find out where my value falls
within it (so the value also needs to be rescaled).

range1 = 26.43534;
range2 = 234.24;
target1 = 0;
target2 = 255;
valueToPlace = 118.12;
scale = (rage2-range1)/(target2-target1);
result = target1+(valueToPlace-range1)/scale;

Or, in this case, 112.50
 
Perfect - Thanks!

Alberto Poblacion said:
range1 = 26.43534;
range2 = 234.24;
target1 = 0;
target2 = 255;
valueToPlace = 118.12;
scale = (rage2-range1)/(target2-target1);
result = target1+(valueToPlace-range1)/scale;

Or, in this case, 112.50
 
I ran into a case when this doesn't work.

range1 = 0;
range2 = 60;
valueToPlace = 86.658;

my result = 368.29650000000004.

-Joe
 
seems your ValueToPlace is out of range (> 60). If it is just the last 4
after all the zeroes that you don't like, you can probably eliminate the
rounding error by limiting the number of decimals you display.

/LM
 
Ok so I made myself look like a fool....

Sometimes it's good to sleep.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top