Skip to content
Jun 23 / Sidney de Koning

Clipping values between 0 and 1

Sometimes its handy to normalize of clamp values between a specific range. You can do this very easily with Math.min() and Math.max().
Here is a code snippet to show you how:

Clipping values to stay between 0 and 1

  1. // clipping values for volume
  2. function set volume( value:Number ):void {
  3.     _soundTransform.volume = Math.min(Math.max(value, 0), 1);
  4. }

Please consider to buying me a coffee.

One Comment

Leave a comment
  1. forex robot / Jun 29 2010

    Great information! I’ve been looking for something like this for a while now. Thanks!

Leave a comment