Estimate JS interest



  • I have two variables.

    let valMax = 29
    let valNow = 15
    let valEnter = ?
    

    variable valMax No change, variable valNow Always change.

    variables valEnter I need to get the result out as a percentage, How to explain to Javascript that 29 is 100%.



  • The simplest thing is

    100 * текущее / максимальное
    

    General formula

    100 * (current - min) / (max - min)
    

    a Reflecting borders and the inability to overcome them (in some cases no more than 100 per cent or less than 0 per cent)

    (current < min) ? 0 : (current > max) ? 100 : (100 * (current - min) / (max - min))
    

Log in to reply
 

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2