is new.
java.lang.Objectjava.math.MathContext
public final class MathContext
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:
precision:
roundingMode: a
RoundingMode
Since:
1.5
| Field Summary | |
|---|---|
| static MathContext |
DECIMAL128
A MathContext object with a precision setting matching the IEEE 754R Decimal128 format, 34 digits, and a rounding mode of HALF_EVEN |
| static MathContext |
DECIMAL32
A MathContext object with a precision setting matching the IEEE 754R Decimal32 format, 7 digits, and a rounding mode of HALF_EVEN |
| static MathContext |
DECIMAL64
A MathContext object with a precision setting matching the IEEE 754R Decimal64 format, 16 digits, and a rounding mode of HALF_EVEN |
| static MathContext |
UNLIMITED
A MathContext object whose settings have the values required for unlimited precision arithmetic. |
| Constructor Summary | |
|---|---|
|
MathContext
(int setPrecision) Constructs a new MathContext with the specified precision and the HALF_UP |
|
|
MathContext
(int setPrecision,
RoundingMode
Constructs a new MathContext with a specified precision and rounding mode. |
|
|
MathContext
(
String
Constructs a new MathContext from a string. |
|
| Method Summary | |
|---|---|
| boolean |
equals
(
Object
Compares this MathContext with the specified Object for equality. |
| int |
getPrecision
() Returns the precision setting. |
| RoundingMode |
getRoundingMode
() Returns the roundingMode setting. |
| int |
hashCode
() Returns the hash code for this
MathContext.
|
| String |
toString
() Returns the string representation of this
MathContext.
|
| Methods inherited from class java.lang. Object |
|---|
| clone , finalize , getClass , notify , notifyAll , wait , wait , wait |
| Field Detail |
|---|
public static final MathContext UNLIMITED
public static final MathContext DECIMAL32
public static final MathContext DECIMAL64
public static final MathContext DECIMAL128
| Constructor Detail |
|---|
public MathContext(int setPrecision)
if the
setPrecision
parameter
is
less than zero.
public MathContext(int setPrecision,
RoundingMode setRoundingMode)
- if the setPrecision parameter is less than zero.
NullPointerException
- if the rounding mode argument is null
public MathContext(String val)
An IllegalArgumentException is thrown if the precision section of the string is out of range (< 0) or the string is not in the format created by the toString() method.
if the
precision
section is
of
incorrect format
NullPointerException
- if the argument is null
| Method Detail |
|---|
public int getPrecision()
public RoundingMode getRoundingMode()
public boolean equals(Object x)
object
public int hashCode()
MathContext.
public String toString()
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,
"precision=",
"roundingMode=",
For example:
precision=9 roundingMode=HALF_UPAdditional words may be appended to the result of toString in the future if more properties are added to this class.
settings