Access keys

NumberUtil

Kind of class: class
Inherits from: none
Version: 02/14/07
Author: Aaron Clinger, David Nelson
Classpath: org.casaframework.util.NumberUtil
File last modified: Wednesday, 14 February 2007, 14:23:45

Class methods

addLeadingZero

static function addLeadingZero (
num:Number) : String
Adds a leading zero for numbers less than ten.
Parameters:
num:
Number to add leading zero.
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, val1:Number, val2:Number) : Boolean
Determines if the value is included within the range.
Parameters:
num :
Number to determine if it's included in the range.
val1:
Beginning value of the range.
val2:
Ending 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.

makeBetween

static function makeBetween (
num:Number, val1:Number, val2:Number) : Number
Determines if value falls within the range; if not it is snapped to the nearest range value.
Parameters:
num :
Number to determine if it's included in the range.
val1:
Beginning value of the range.
val2:
Ending 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