# NumberUtil

Kind of class: class none 06/28/07 Aaron Clinger, David Nelson org.casaframework.util.NumberUtil Sunday, 19 August 2007, 13:43:36

## Class methods

Parameters:
num:
Returns:
Number as a String; if the number was less than ten the number will have a leading zero.

### createStepsBetween

static function createStepsBetween (begin:Number, end:Number, steps:Number) : Array
Creates evenly spaced numerical increments between two numbers.
Parameters:
begin:
The starting value.
end :
The ending value.
steps:
The number of increments between the starting and ending values.
Returns:
Returns an Array comprised of the increments between the two values.
Example:
```trace(NumberUtil.createStepsBetween(0, 5, 4)); // Traces 1,2,3,4
trace(NumberUtil.createStepsBetween(1, 3, 3)); // Traces 1.5,2,2.5```

### format

static function format (numberToFormat:Number, minLength:Number, thouDelim:String, fillChar:String) : String
Formats a number.
Parameters:
numberToFormat:
The number you wish to format.
minLength :
The minimum length of the number.
thouDelim :
[optional] The character used to seperate thousands; defaults to none.
fillChar :
[optional] The leading character used to make the number the minimum length; defaults to `0`.
Returns:
Returns the formated number as a String.
Example:
`trace(NumberUtil.format(1234567, 8, ",")); // Traces 01,234,567`

### getOrdinalSuffix

static function getOrdinalSuffix (num:Number) : String
Finds the English ordinal suffix for the number given.
Parameters:
num:
Number to find the ordinal suffix of.
Returns:
Returns the suffix for the number, 2 characters.
Example:
`trace(32 + NumberUtil.getOrdinalSuffix(32)); // Traces 32nd`

### isBetween

static function isBetween (num:Number, startValue:Number, endValue:Number) : Boolean
Determines if the value is included within a range.
Parameters:
num :
Number to determine if it's included in the range.
startValue:
First value of the range.
endValue :
Second value of the range.
Returns:
Returns `true` if the number falls within the range; otherwise `false`.

### isEven

static function isEven (num:Number) : Boolean
Determines if the number is even.
Parameters:
num:
A number to determine if it is divisible by `2`.
Returns:
Returns `true` if the number is even; otherwise `false`.

### isInteger

static function isInteger (num:Number) : Boolean
Determines if the number is an integer.
Parameters:
num:
A number to determine if it contains no decimal values.
Returns:
Returns `true` if the number is an integer; otherwise `false`.

### isOdd

static function isOdd (num:Number) : Boolean
Determines if the number is odd.
Parameters:
num:
A number to determine if it is not divisible by `2`.
Returns:
Returns `true` if the number is odd; otherwise `false`.

### isPrime

static function isPrime (num:Number) : Boolean
Determines if the number is prime.
Parameters:
num:
A number to determine if it is only divisible by 1 and itself.
Returns:
Returns `true` if the number is prime; otherwise `false`.

### makeBetween

static function makeBetween (num:Number, startValue:Number, endValue:Number) : Number
Determines if value falls within a range; if not it is snapped to the nearest range value.
Parameters:
num :
Number to determine if it's included in the range.
startValue:
First value of the range.
endValue :
Second value of the range.
Returns:
Returns either the number as passed, or its value once snapped to nearest range value.

### max

static function max (val1:Number, val2:Number) : Number
Evaluates `val1` and `val2` and returns the larger value. Unlike `Math.max` this method will return the defined value if the other value is `undefined`.
Parameters:
val1:
A number or expression to compare.
val2:
A number or expression to compare.
Returns:
Returns the largest value, or the value out of the two that is defined.

### min

static function min (val1:Number, val2:Number) : Number
Evaluates `val1` and `val2` and returns the smaller value. Unlike `Math.min` this method will return the defined value if the other value is `undefined`.
Parameters:
val1:
A number or expression to compare.
val2:
A number or expression to compare.
Returns:
Returns the smallest value, or the value out of the two that is defined.

### randomInteger

static function randomInteger (min:Number, max:Number) : Number
Creates a random integer within the defined range.
Parameters:
min:
The minimum number the random integer can be.
min:
The maximum number the random integer can be.
Returns:
Returns a random integer within the range.

### roundDecimalToPlace

static function roundDecimalToPlace (num:Number, place:Number) : Number
Rounds a number's decimal value to a specific place.
Parameters:
num :
The number to round.
place:
The decimal place to round.
Returns:
Returns the value rounded to the defined place.
Example:
```trace(NumberUtil.roundToPlace(3.14159, 2)); // Traces 3.14
trace(NumberUtil.roundToPlace(3.14159, 3)); // Traces 3.142```