Packagesystem.comparators
Classpublic class NumberComparator
InheritanceNumberComparator Inheritance Object
Implements Comparator

This comparator compare two Number objects.

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
     



Public Properties
 PropertyDefined 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
Public Methods
 MethodDefined 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
Property Detail
fixedproperty
public var fixed:Boolean

Indicates if the two numbers are round to the specified number of decimal places (see the fractionDigits property).

fractionDigitsproperty 
public var fractionDigits:uint

An integer between 0 and 20, inclusive, that represents the desired number of decimal places.

Constructor Detail
NumberComparator()Constructor
public function NumberComparator(fixed:Boolean = false, fractionDigits:uint = 0)

Creates a new NumberComparator instance.

Parameters
fixed: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.
Method Detail
compare()method
public function compare(o1:*, o2:*, options:* = null):int

Returns 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)

Returns
int

  • -1 if o1 is "lower" than (less than, before, etc.) o2 ;
  • 1 if o1 is "higher" than (greater than, after, etc.) o2 ;
  • 0 if o1 and o2 are equal.

  • Throws
    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).