Scaling between two number ranges
Use percentages:
xMax = 10;
xMin = 1;
yMax = 559.22;
yMin = 300.77;
percent = (inputY - yMin) / (yMax - yMin);
outputX = percent * (xMax - xMin) + xMin;
function convertRange( value, r1, r2 ) {
return ( value - r1[ 0 ] ) * ( r2[ 1 ] - r2[ 0 ] ) / ( r1[ 1 ] - r1[ 0 ] ) + r2[ 0 ];
}
convertRange( 328.17, [ 300.77, 559.22 ], [ 1, 10 ] );
>>> 1.9541497388276272