Package | org.as3coreaddendum.system.comparators |
Class | public class NumberComparator |
Inheritance | NumberComparator ![]() |
Implements | IComparator |
Number
objects.
See also
Property | Defined By | ||
---|---|---|---|
decimalPlaces : int
Defines the number of decimal places to be considered in the comparison. | NumberComparator | ||
useDecimalPlaces : Boolean
Defines if both numbers should be rounded by the decimalPlaces property. | NumberComparator |
Method | Defined By | ||
---|---|---|---|
NumberComparator(useDecimalPlaces:Boolean = false, decimalPlaces:int = 0)
Constructor, creates a new NumberComparator object. | NumberComparator | ||
compare(o1:*, o2:*):int
Performs the comparison between the two arguments. | NumberComparator | ||
toString():String
Returns the string representation of this object. | NumberComparator |
decimalPlaces | property |
decimalPlaces:int
Defines the number of decimal places to be considered in the comparison. Must be an integer between 0 and 20.
public function get decimalPlaces():int
public function set decimalPlaces(value:int):void
RangeError — if is assigned a value out of the 0-20 range.
|
useDecimalPlaces | property |
useDecimalPlaces:Boolean
Defines if both numbers should be rounded by the decimalPlaces
property.
public function get useDecimalPlaces():Boolean
public function set useDecimalPlaces(value:Boolean):void
NumberComparator | () | Constructor |
public function NumberComparator(useDecimalPlaces:Boolean = false, decimalPlaces:int = 0)
Constructor, creates a new NumberComparator
object.
useDecimalPlaces:Boolean (default = false ) — Indicates if both numbers should be rounded by the decimalPlaces property.
| |
decimalPlaces:int (default = 0 ) — The number of decimal places to be considered in the comparison. Must be an integer between 0 and 20.
|
ArgumentError — if useDecimalPlaces argument is sent false but some value is sent to decimalPlaces argument.
| |
RangeError — if the decimalPlaces argument is out of the 0-20 range.
|
compare | () | method |
public function compare(o1:*, o2:*):int
Performs the comparison between the two arguments.
Parameters
o1:* — The first Number object to be compared.
| |
o2:* — The second Number object to be compared.
|
int — A negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
|
ArgumentError — if any of the arguments is not of type Number .
|
toString | () | method |
public function toString():String
Returns the string representation of this object.
ReturnsString — the string representation of the this object.
|
import org.as3coreaddendum.system.comparators.NumberComparator; var c:NumberComparator = new NumberComparator(); c.compare(0, 0); // 0 c.compare(1, 1); // 0 c.compare(0, 1); // -1 c.compare(94, 56); // 1 c.compare(-38, -27); // -1 c.compare(2.5, 2.5); // 0 c.compare(2.54, 2.54); // 0 c.compare(2.54, 2.56); // -1 c.compare(2.567, 2.567); // 0 c.compare(2.5678, 2.5677); // 1 c.compare(2.5678, 2.5674); // 1 c.compare(2.5674, 2.5678); // -1
import org.as3coreaddendum.system.comparators.NumberComparator; var c1:NumberComparator = new NumberComparator(true, 1); c1.compare(2.5, 2.5); // 0 c1.compare(2.54, 2.54); // 0 c1.compare(2.54, 2.56); // -1 c1.compare(2.567, 2.567); // 0 c1.compare(2.5678, 2.5677); // 0 c1.compare(2.5678, 2.5674); // 0 c1.compare(2.5674, 2.5678); // 0
import org.as3coreaddendum.system.comparators.NumberComparator; var c2:NumberComparator = new NumberComparator(true, 2); c2.compare(2.5, 2.5); // 0 c2.compare(2.54, 2.54); // 0 c2.compare(2.54, 2.56); // -1 c2.compare(2.567, 2.567); // 0 c2.compare(2.5678, 2.5677); // 0 c2.compare(2.5678, 2.5674); // 0 c2.compare(2.5674, 2.5678); // 0
import org.as3coreaddendum.system.comparators.NumberComparator; var c3:NumberComparator = new NumberComparator(true, 3); c3.compare(2.5, 2.5); // 0 c3.compare(2.54, 2.54); // 0 c3.compare(2.54, 2.56); // -1 c3.compare(2.567, 2.567); // 0 c3.compare(2.5678, 2.5677); // 0 c3.compare(2.5678, 2.5674); // 1 c3.compare(2.5674, 2.5678); // -1
import org.as3coreaddendum.system.comparators.NumberComparator; var c4:NumberComparator = new NumberComparator(true, 4); c4.compare(2.5, 2.5); // 0 c4.compare(2.54, 2.54); // 0 c4.compare(2.54, 2.56); // -1 c4.compare(2.567, 2.567); // 0 c4.compare(2.5678, 2.5677); // 1 c4.compare(2.5678, 2.5674); // 1 c4.compare(2.5674, 2.5678); // -1