| Package | system.comparators |
| Class | public class NumberComparator |
| Inheritance | NumberComparator Object |
| Implements | Comparator |
Example :
import system.comparators.NumberComparator ;
var c:NumberComparator = new NumberComparator() ;
trace( c.compare(0,0) ) ; // 0
trace( c.compare(1,1) ) ; // 0
trace( c.compare(-1,-1) ) ; // 0
trace( c.compare(0.1,0.1) ) ; // 0
trace( c.compare( Number(Math.cos(25)) , 0.9912028118634736 ) ) ; // 0
trace( c.compare(1, 0) ) ; // 1
trace( c.compare(0, 1) ) ; // -1
c.fixed = true ;
c.fractionDigits = 3 ;
trace( c.compare( 1.2356 , 1.2358 ) ) ; // 0
c.fractionDigits = 4 ;
trace( c.compare( 1.2356 , 1.2358 ) ) ; // -1
c.fractionDigits = 0 ;
trace( c.compare( Math.cos(25) , 1 ) ) ; // 0
| Property | Defined By | ||
|---|---|---|---|
| fixed : Boolean
Indicates if the two numbers are round to the specified number of decimal places (see the fractionDigits property). | NumberComparator | ||
| fractionDigits : uint
An integer between 0 and 20, inclusive, that represents the desired number of decimal places. | NumberComparator | ||
| Method | Defined By | ||
|---|---|---|---|
NumberComparator(fixed:Boolean = false, fractionDigits:uint = 0)
Creates a new NumberComparator instance. | NumberComparator | ||
compare(o1:*, o2:*, options:* = null):int
Returns an integer value to compare two Number objects. | NumberComparator | ||
| fixed | property |
public var fixed:BooleanIndicates if the two numbers are round to the specified number of decimal places (see the fractionDigits property).
| fractionDigits | property |
public var fractionDigits:uintAn integer between 0 and 20, inclusive, that represents the desired number of decimal places.
| NumberComparator | () | Constructor |
public function NumberComparator(fixed:Boolean = false, fractionDigits:uint = 0)Creates a new NumberComparator instance.
Parametersfixed:Boolean (default = false) — Indicates if the two numbers are round to the specified number of decimal places (see the fractionDigits property).
| |
fractionDigits:uint (default = 0) — An integer between 0 and 20, inclusive, that represents the desired number of decimal places.
|
| compare | () | method |
public function compare(o1:*, o2:*, options:* = null):intReturns an integer value to compare two Number objects.
Parameters
o1:* — the first Number object to compare.
| |
o2:* — the second Number object to compare.
| |
options:* (default = null) |
int —
|
ArgumentError — if compare(a, b) and 'a' and 'b' must be Number objects.
| |
RangeError — Throws an exception if the fractionDigits argument is outside the range 0 to 20 (only if fixed is true).
|