Convert a number range to another range

Today I will share with you one very cool tricks used in Graphics and visualization.

The problem is you have given one range, for example, 0-10, and you have to convert this range to 0-100. Converting range from one scale to another is a typical math problem.
Use the following formula to scale one range to another.

const rescale=(value)=>{
   const oldScale=[0,10];
   const newScale=[0,100];
   const scale=(newScale[1]-newScale[0])/(oldScale[1]-oldScale[0])*(value-oldScale[0])+newScale[0];
   return scale;


Please do not post any spam link in the comment box😊

Post a Comment (0)
Previous Post Next Post