Select Page

Quite often I need to restrict a number to a range with a defined maximum and minimum value. Rather than using if else statements you can do this simply with Math.max and Math.min:

var restricted_value:Number = Math.max(MIN_VALUE, Math.min(MAX_VALUE, value));