0

I have a project going where i use a vue-slider for adjusting volume, and at the same time i also use vue-slider`s process to show current level on the actual output, however i have a mathematical problem thats above my head of thinking.

Lets say i have read a level of -15db, now my scale is going from -40db to +20db, however vue-slider`s process does not care about this value, it value is based on percentage, from 0 - 100.

So the question is, what equation can i use to get percentage(between 0-100%) of value(-15) within min(-40) and max(20)?

Example of the slider:

enter image description here

Stian Blåsberg
  • 115
  • 2
  • 8

1 Answers1

0

Solution i used are following:

let percent = 0
if (level > chGainMin) {
  const translator = Math.abs(chGainMin)
  const newMin = chGainMin + translator
  const newMax = chGainMax + translator
  const newLevel = level + translator
  percent = ((newLevel-newMin)*100) / (newMax-newMin)
}

Using abs to turn negative minimum to a positive number, and append this number to min, max and value. Then calculate the percentage as usual.

Stian Blåsberg
  • 115
  • 2
  • 8