This documentation differs from the official API.
Jadeite adds
extra features to the API including:
variable font sizes,
constructions examples,
placeholders for classes and methods, and auto-generated “See Also” links.
Additionally it
is missing some items found in standard Javadoc documentation, including:
generics type information,
“Deprecated” tags and comments,
“See Also” links,
along with other minor differences.
Please send any questions or feedback to
bam@cs.cmu.edu.
java.math
class MathContext
- All Implemented Interfaces:
- Serializable
-
Most common way to construct:
-
MathContext mc = new MathContext(40);
Based on 32 examples
public final class MathContext
extends Object
implements Serializable
Immutable objects which encapsulate the context settings which
describe certain rules for numerical operators, such as those
implemented by the {@link BigDecimal} class.
The base-independent settings are:
- {@code precision}:
the number of digits to be used for an operation; results are
rounded to this precision
- {@code roundingMode}:
a {@link RoundingMode} object which specifies the algorithm to be
used for rounding.
Field Summary |
static MathContext |
DECIMAL128
A object with a precision setting
matching the IEEE 754R Decimal128 format, 34 digits, and a
rounding mode of java.math.RoundingMode.HALF_EVEN, the
IEEE 754R default. |
static MathContext |
DECIMAL32
A object with a precision setting
matching the IEEE 754R Decimal32 format, 7 digits, and a
rounding mode of java.math.RoundingMode.HALF_EVEN, the
IEEE 754R default. |
static MathContext |
DECIMAL64
A object with a precision setting
matching the IEEE 754R Decimal64 format, 16 digits, and a
rounding mode of java.math.RoundingMode.HALF_EVEN, the
IEEE 754R default. |
static MathContext |
UNLIMITED
A object whose settings have the values
required for unlimited precision arithmetic. |
Constructor Summary |
Constructs a new with the specified
precision and the java.math.RoundingMode.HALF_UP rounding
mode.
|
Constructs a new with a specified
precision and rounding mode.
|
Constructs a new from a string.
|
Method Summary |
boolean |
Compares this with the specified
for equality.
|
int |
Returns the setting.
|
RoundingMode |
Returns the roundingMode setting.
|
int |
Returns the hash code for this .
|
String |
Returns the string representation of this .
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
DECIMAL128
public static final MathContext DECIMAL128
-
A {@code MathContext} object with a precision setting
matching the IEEE 754R Decimal128 format, 34 digits, and a
rounding mode of {@link RoundingMode#HALF_EVEN HALF_EVEN}, the
IEEE 754R default.
DECIMAL32
public static final MathContext DECIMAL32
-
A {@code MathContext} object with a precision setting
matching the IEEE 754R Decimal32 format, 7 digits, and a
rounding mode of {@link RoundingMode#HALF_EVEN HALF_EVEN}, the
IEEE 754R default.
DECIMAL64
public static final MathContext DECIMAL64
-
A {@code MathContext} object with a precision setting
matching the IEEE 754R Decimal64 format, 16 digits, and a
rounding mode of {@link RoundingMode#HALF_EVEN HALF_EVEN}, the
IEEE 754R default.
UNLIMITED
public static final MathContext UNLIMITED
-
A {@code MathContext} object whose settings have the values
required for unlimited precision arithmetic.
The values of the settings are:
precision=0 roundingMode=HALF_UP
MathContext
public MathContext(int setPrecision)
-
Constructs a new {@code MathContext} with the specified
precision and the {@link RoundingMode#HALF_UP HALF_UP} rounding
mode.
- Parameters:
setPrecision
- The non-negative {@code int} precision setting.
MathContext
public MathContext(int setPrecision,
RoundingMode setRoundingMode)
-
Constructs a new {@code MathContext} with a specified
precision and rounding mode.
- Parameters:
setPrecision
- The non-negative {@code int} precision setting.
setRoundingMode
- The rounding mode to use.
MathContext
public MathContext(String val)
-
Constructs a new {@code MathContext} from a string.
The string must be in the same format as that produced by the
{@link #toString} method.
An {@code IllegalArgumentException} is thrown if the precision
section of the string is out of range ({@code < 0}) or the string is
not in the format created by the {@link #toString} method.
- Parameters:
val
- The string to be parsed
equals
public boolean equals(Object x)
-
Compares this {@code MathContext} with the specified
{@code Object} for equality.
- Overrides:
equals
in class Object
- Parameters:
x
- {@code Object} to which this {@code MathContext} is to
be compared.
- Returns:
- {@code true} if and only if the specified {@code Object} is
a {@code MathContext} object which has exactly the same
settings as this object
getPrecision
public int getPrecision()
-
Returns the {@code precision} setting.
This value is always non-negative.
- Returns:
- an {@code int} which is the value of the {@code precision}
setting
getRoundingMode
public RoundingMode getRoundingMode()
-
Returns the roundingMode setting.
This will be one of
{@link RoundingMode#CEILING},
{@link RoundingMode#DOWN},
{@link RoundingMode#FLOOR},
{@link RoundingMode#HALF_DOWN},
{@link RoundingMode#HALF_EVEN},
{@link RoundingMode#HALF_UP},
{@link RoundingMode#UNNECESSARY}, or
{@link RoundingMode#UP}.
- Returns:
- a {@code RoundingMode} object which is the value of the
{@code roundingMode} setting
hashCode
public int hashCode()
-
Returns the hash code for this {@code MathContext}.
- Overrides:
hashCode
in class Object
- Returns:
- hash code for this {@code MathContext}
toString
public String toString()
-
Returns the string representation of this {@code MathContext}.
The {@code String} returned represents the settings of the
{@code MathContext} object as two space-delimited words
(separated by a single space character, '\u0020',
and with no leading or trailing white space), as follows:
-
The string {@code "precision="}, immediately followed
by the value of the precision setting as a numeric string as if
generated by the {@link Integer#toString(int) Integer.toString}
method.
-
The string {@code "roundingMode="}, immediately
followed by the value of the {@code roundingMode} setting as a
word. This word will be the same as the name of the
corresponding public constant in the {@link RoundingMode}
enum.
For example:
precision=9 roundingMode=HALF_UP
Additional words may be appended to the result of
{@code toString} in the future if more properties are added to
this class.
- Overrides:
toString
in class Object
- Returns:
- a {@code String} representing the context settings
This documentation differs from the official API.
Jadeite adds
extra features to the API including:
variable font sizes,
constructions examples,
placeholders for classes and methods, and auto-generated “See Also” links.
Additionally it
is missing some items found in standard Javadoc documentation, including:
generics type information,
“Deprecated” tags and comments,
“See Also” links,
along with other minor differences.
Please send any questions or feedback to
bam@cs.cmu.edu.
This page displays the
Jadeite version of the documention, which is derived from the offical documentation that contains this copyright notice:
The official Sun™ documentation can be found here at
http://java.sun.com/javase/6/docs/api/.