Packagecom.gestureworks.cml.utils
Classpublic class NumberUtils
InheritanceNumberUtils Inheritance Object

The NumberUtils utility is a collection of static methods for working with numbers.
        //trace(NumberUtils.map(20, 0, 100, 220, 550)); 
        //trace(NumberUtils.roundNumber(100.3245, 1)); 
        //trace(NumberUtils.randomNumber(300, 500)); 
     
     

See also

LinkedMap


Public Methods
 MethodDefined By
  
Constructor
NumberUtils
  
map(num:Number, min1:Number, max1:Number, min2:Number, max2:Number, round:Boolean = false, constrainMin:Boolean = true, constrainMax:Boolean = true):Number
[static] Linearly maps an incoming value from one range to another
NumberUtils
  
randomNumber(minNum:Number, maxNum:Number):Number
[static] Returns a random number within a specified range
NumberUtils
  
roundNumber(num:Number, decimal:Number):Number
[static] Rounds a number to decimal places
NumberUtils
Constructor Detail
NumberUtils()Constructor
public function NumberUtils()

Constructor

Method Detail
map()method
public static function map(num:Number, min1:Number, max1:Number, min2:Number, max2:Number, round:Boolean = false, constrainMin:Boolean = true, constrainMax:Boolean = true):Number

Linearly maps an incoming value from one range to another

Parameters

num:Number — Incoming value to be mapped
 
min1:Number — Incoming minimum range value
 
max1:Number — Incoming maximum range value
 
min2:Number — Outgoing minimum range value
 
max2:Number — Outgoing maximum range value
 
round:Boolean (default = false) — Whether the returned value is rounded to nearest integer
 
constrainMin:Boolean (default = true) — Whether the returned value is constrained to the minumim value
 
constrainMax:Boolean (default = true) — Whether the returned value is constrained to the maximum value

Returns
Number — Mapped value
randomNumber()method 
public static function randomNumber(minNum:Number, maxNum:Number):Number

Returns a random number within a specified range

Parameters

minNum:Number
 
maxNum:Number

Returns
Number
roundNumber()method 
public static function roundNumber(num:Number, decimal:Number):Number

Rounds a number to decimal places

Parameters

num:Number
 
decimal:Number

Returns
Number