My Math Forum Transform a number?

 Elementary Math Fractions, Percentages, Word Problems, Equations, Inequations, Factorization, Expansion

 April 15th, 2015, 12:31 AM #1 Newbie   Joined: Oct 2014 From: Mars Posts: 27 Thanks: 0 Transform a number? Hi, can someone please help me to write a formula to transform a number. I'm trying to write a function with 5 parameters: 1) The value to be transformed 2) The values minimum range 3) The values maximum range 4) The destinations minimum range 5) The destinations maximum range For example, lets say I have a value 4 (which belongs in a system that goes from 4 to 10), and I want to transform it into a number (newValue) which ranges from 400 to 1000. At the moment, this is the formula I have: newValue = (value/valuesMax-valuesMin) * (destinationsMax-destinationsMin) So if I do: (4/10-4) * (1000-400) = 400 (which is correct) The problem is when I try to use negative numbers, this formula stops working... Example: (5/10-0) * (1 - -1) = 1 (which is wrong. Should be 0 since 0 is the middle of -1 and 1, and the values we gave it were 5 in a range of 0 to 10). Thanks in advance, A.
 April 17th, 2015, 01:09 AM #2 Senior Member   Joined: Apr 2014 From: UK Posts: 793 Thanks: 295 To work out the destination value, you first need to work out where in the source range your value is. This is achieved by (value-valueMin)/(valueMax-valueMin) and gives a value between 0 and 1 Taking the first example of 4, 0 and 10 for value, valueMin and valueMax we get: (4-4)/(10-4) = 0, which is correct as it is at the bottom of your range. Next we need to convert this range value to a position in your destination range, which is achieved by: (range * (DesinationMax - DestinationMin) ) + DestinationMin So, again with the first example we get: (0 * (1000 - 400) ) + 400 = 400, which is correct. Putting both parts together we get: ((value-valueMin)/(valueMax-valueMin) * (DesinationMax - DestinationMin) ) + DestinationMin Now if we try the 2nd example with 5, 0, 10, -1 and 1 for the 5 variables, we get: ((5 - 0)/(10 - 0) * (1 - -1)) + -1 = 0, which is correct
 April 17th, 2015, 11:41 PM #3 Newbie   Joined: Oct 2014 From: Mars Posts: 27 Thanks: 0 Thanks very much!!

 Tags number, transform

### transform a number

Click on a term to search for related topics.
 Thread Tools Display Modes Linear Mode

 Similar Threads Thread Thread Starter Forum Replies Last Post Shen Elementary Math 2 June 5th, 2014 08:50 AM Frank Lucas Applied Math 1 May 25th, 2013 10:11 AM ilovetheflowguy Algebra 9 February 27th, 2012 03:44 PM progrocklover Real Analysis 1 March 24th, 2011 09:29 PM aptx4869 Real Analysis 5 September 3rd, 2008 01:47 AM

 Contact - Home - Forums - Cryptocurrency Forum - Top