Creating a percentage out of variables that set min and max

Basically, I need to set a max value that would be considered 100% and a min value that would 0%, then look at another variable’s float to decided what percentage it is at.

For instance:

var randomNumber : float; // this number could be anything, but I only care when it is between the min and max values
var max = 2; // the 100% value
var min = .5; // the 0 value

var percentage = x;

All I need is var percentage to be a value between 0 and 1. How do I calculate that? Or where should I even look for help on this?

Thanks!

Mathf.InverseLerp

–Eric

1 Like