public final class MathContext
extends Object implements Serializable
| java.lang.Object | |
| java.math.MathContext | |
不可变的对象,描述类 BigDecimal提供的数值操作的舍入模式和数字精度等设置。
Fields |
|
|---|---|
public static final MathContext |
DECIMAL128 A |
public static final MathContext |
DECIMAL32 |
public static final MathContext |
DECIMAL64 |
public static final MathContext |
UNLIMITED 一个 |
Public constructors |
|
|---|---|
MathContext(int precision) 构造一个新的 |
|
MathContext(int precision, RoundingMode roundingMode) 用指定的精度和指定的舍入模式构造一个新的 |
|
MathContext(String s) 从字符串构造一个新的 |
|
公共方法(Public methods) |
|
|---|---|
boolean |
equals(Object x) 如果x是具有与此 |
int |
getPrecision() 返回精度。 |
RoundingMode |
getRoundingMode() 返回舍入模式。 |
int |
hashCode() 返回此 |
String |
toString() 返回此 |
继承方法(Inherited methods) |
|
|---|---|
java.lang.Object
|
|
MathContext (int precision)
构造一个新的MathContext与指定的精度和与舍入模式HALF_UP 。 如果传递的精度为零,那么这意味着计算必须准确执行,在这种情况下舍入模式是不相关的。
| 参数(Parameters) | |
|---|---|
precision |
int: the precision for the new MathContext. |
| 抛出异常(Throws) | |
|---|---|
IllegalArgumentException |
if precision < 0. |
MathContext (int precision,
RoundingMode roundingMode)
用指定的精度和指定的舍入模式构造一个新的MathContext 。 如果传递的精度为零,那么这意味着计算必须准确执行,在这种情况下舍入模式是不相关的。
| 参数(Parameters) | |
|---|---|
precision |
int: the precision for the new MathContext. |
roundingMode |
RoundingMode: the rounding mode for the new MathContext. |
| 抛出异常(Throws) | |
|---|---|
IllegalArgumentException |
if precision < 0. |
NullPointerException |
if roundingMode is null. |
MathContext (String s)
从一个字符串构造一个新的MathContext 。 字符串必须指定要使用的精度和舍入模式,并且必须遵循以下语法:“precision = <precision> roundingMode = <roundingMode>”这与toString()方法返回的格式相同。
| 参数(Parameters) | |
|---|---|
s |
String
|
| 抛出异常(Throws) | |
|---|---|
IllegalArgumentException |
if the string is not in the correct format or if the precision specified is < 0. |
boolean equals (Object x)
如果x是具有与此 MathContext实例相同的精度设置和相同舍入模式的 MathContext ,则返回true。
| 参数(Parameters) | |
|---|---|
x |
Object: object to be compared. |
| 返回(Returns) | |
|---|---|
boolean |
true if this MathContext instance is equal to the x argument; false otherwise. |
int getPrecision ()
返回精度。 精度是用于操作的位数。 结果四舍五入到这个精度。 精度保证是非负的。 如果精度为零,那么必须精确执行计算,在这种情况下结果不会被舍入。
| 返回(Returns) | |
|---|---|
int |
the precision. |
RoundingMode getRoundingMode ()
返回舍入模式。 舍入模式是用于对结果进行舍入的策略。
舍入模式是以下之一 UP , DOWN , CEILING , FLOOR , HALF_UP , HALF_DOWN , HALF_EVEN ,或 UNNECESSARY 。
| 返回(Returns) | |
|---|---|
RoundingMode |
the rounding mode. |
int hashCode ()
返回此 MathContext实例的哈希码。
| 返回(Returns) | |
|---|---|
int |
the hash code for this MathContext. |
String toString ()
返回此MathContext实例的字符串表示形式。 该字符串的格式为"precision=<precision> roundingMode=<roundingMode>" ,其中<precision>是描述用于操作的位数的整数, <roundingMode>是舍入模式的字符串表示形式。
| 返回(Returns) | |
|---|---|
String |
a string representation for this MathContext instance |