Packageorg.granite.math
Classpublic final class MathContext
Implementsflash.utils.IExternalizable

Immutable objects which encapsulate the context settings which describe certain rules for numerical operators, such as those implemented by the BigDecimal class.

The base-independent settings are:

  1. precision: the number of digits to be used for an operation; results are rounded to this precision
  2. roundingMode: a RoundingMode object which specifies the algorithm to be used for rounding.
This class is basically an ActionScript3 port of the Java class java.math.MathContext originally written by Mike Cowlishaw and Joseph D. Darcy.

See also

RoundingMode
BigDecimal


Public Properties
 PropertyDefined by
  precision : int
[read-only] The number of digits to be used for an operation.
MathContext
  roundingMode : RoundingMode
[read-only] The rounding algorithm to be used for an operation.
MathContext
Public Methods
 MethodDefined by
  
MathContext(precision:int = 0, roundingMode:RoundingMode = null)
Constructs a new MathContext with a specified precision and rounding mode.
MathContext
  
equals(o:*):Boolean
Compares this MathContext with the specified Object for equality.
MathContext
  
[static] Returns a new MathContext from a string.
MathContext
  
toString():String
Returns the string representation of this MathContext.
MathContext
Public Constants
 ConstantDefined by
  DECIMAL128 : MathContext
[static] A MathContext object with a precision setting matching the IEEE 754R Decimal128 format, 34 digits, and a rounding mode of RoundingMode.HALF_EVEN, the IEEE 754R default.
MathContext
  DECIMAL32 : MathContext
[static] A MathContext object with a precision setting matching the IEEE 754R Decimal32 format, 7 digits, and a rounding mode of RoundingMode.HALF_EVEN, the IEEE 754R default.
MathContext
  DECIMAL64 : MathContext
[static] A MathContext object with a precision setting matching the IEEE 754R Decimal64 format, 16 digits, and a rounding mode of RoundingMode.HALF_EVEN, the IEEE 754R default.
MathContext
  UNLIMITED : MathContext
[static] A MathContext object whose settings have the values required for unlimited precision arithmetic.
MathContext
Property detail
precisionproperty
precision:int  [read-only]

The number of digits to be used for an operation. A value of 0 indicates that unlimited precision (as many digits as are required) will be used. Note that leading zeros (in the coefficient of a number) are never significant.
precision will always be non-negative.

Implementation
    public function get precision():int
roundingModeproperty 
roundingMode:RoundingMode  [read-only]

The rounding algorithm to be used for an operation.

Implementation
    public function get roundingMode():RoundingMode

See also

Constructor detail
MathContext()constructor
public function MathContext(precision:int = 0, roundingMode:RoundingMode = null)

Constructs a new MathContext with a specified precision and rounding mode.

Parameters
precision:int (default = 0) — The non-negative int precision setting.
 
roundingMode:RoundingMode (default = null) — The rounding mode to use. If this parameter is omitted or null, it is defaulted to RoundingMode.HALF_UP.

Throws
IllegalArgumentError — if the precision parameter is less than zero.

See also

Method detail
equals()method
public function equals(o:*):Boolean

Compares this MathContext with the specified Object for equality.

Parameters
o:*Object to which this MathContext is to be compared.

Returns
Booleantrue if and only if the specified Object is a MathContext object which has exactly the same settings as this object.
forString()method 
public static function forString(s:String):MathContext

Returns a new MathContext from a string. The string must be in the same format as that produced by the toString method.

Parameters
s:String — The string to be parsed

Returns
MathContext — a new MathContext instance according to the supplied parameter.

Throws
IllegalArgumentError — if the precision section is out of range or the string is not in the format created by the toString method.

See also

toString()method 
public function toString():String

Returns the string representation of this MathContext. The String returned represents the settings of the MathContext object as two space-delimited words (separated by a single space character, '\u0020', and with no leading or trailing white space), as follows:

  1. The string "precision=", immediately followed by the value of the precision setting as a numeric string as if generated by the int.toString() method.
  2. The string "roundingMode=", immediately followed by the value of the roundingMode setting as a word. This word will be the same as the name of the corresponding public constant in the RoundingMode enum.

For example: "precision=9 roundingMode=HALF_UP"
Additional words may be appended to the result of toString in the future if more properties are added to this class.

Returns
String — a String representing the context settings.

See also

Constant detail
DECIMAL128constant
public static const DECIMAL128:MathContext

A MathContext object with a precision setting matching the IEEE 754R Decimal128 format, 34 digits, and a rounding mode of RoundingMode.HALF_EVEN, the IEEE 754R default.

See also

DECIMAL32constant 
public static const DECIMAL32:MathContext

A MathContext object with a precision setting matching the IEEE 754R Decimal32 format, 7 digits, and a rounding mode of RoundingMode.HALF_EVEN, the IEEE 754R default.

See also

DECIMAL64constant 
public static const DECIMAL64:MathContext

A MathContext object with a precision setting matching the IEEE 754R Decimal64 format, 16 digits, and a rounding mode of RoundingMode.HALF_EVEN, the IEEE 754R default.

See also

UNLIMITEDconstant 
public static const UNLIMITED:MathContext

A MathContext object whose settings have the values required for unlimited precision arithmetic.
The values of the settings are: precision=0 roundingMode=HALF_UP

See also