public final class MathContext extends Object implements Serializable
BigDecimal
类中实现这些。
基本独立设置:
precision
:用于操作的位数;结果是圆的这个精度roundingMode
:一RoundingMode
对象指定用于舍入算法。BigDecimal
,
RoundingMode
,
Serialized Form
Modifier and Type | Field and Description |
---|---|
static MathContext |
DECIMAL128
一个
MathContext 对象与精度设置匹配的IEEE 754R decimal128格式,34位数字,和舍入模式
HALF_EVEN ,IEEE 754R默认。
|
static MathContext |
DECIMAL32
一个
MathContext 对象与精度设置匹配的IEEE 754R decimal32格式,7位数字,和舍入模式
HALF_EVEN ,IEEE 754R默认。
|
static MathContext |
DECIMAL64
一个
MathContext 对象与精度设置匹配的IEEE 754R decimal64格式,16位数字,和舍入模式
HALF_EVEN ,IEEE 754R默认。
|
static MathContext |
UNLIMITED
一个
MathContext 对象设置的具有无限精度运算所需的值。
|
Constructor and Description |
---|
MathContext(int setPrecision)
构建了一种新的
MathContext 与指定的精度和
HALF_UP 舍入模式。
|
MathContext(int setPrecision, RoundingMode setRoundingMode)
构建与指定的精度的一种新
MathContext 和舍入模式。
|
MathContext(String val)
构建新的
MathContext 从字符串。
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object x)
这
MathContext 与平等的规定
Object 比较。
|
int |
getPrecision()
返回
precision 设置。
|
RoundingMode |
getRoundingMode()
返回roundingmode设置。
|
int |
hashCode()
返回此
MathContext 哈希代码。
|
String |
toString()
这
MathContext 返回的字符串表示形式。
|
public static final MathContext UNLIMITED
MathContext
对象设置的具有无限精度运算所需的值。该设置的值是:
precision=0 roundingMode=HALF_UP
public static final MathContext DECIMAL32
MathContext
对象与精度设置匹配的IEEE 754R decimal32格式,7位数字,和舍入模式
HALF_EVEN
,IEEE 754R默认。
public static final MathContext DECIMAL64
MathContext
对象与精度设置匹配的IEEE 754R decimal64格式,16位数字,和舍入模式
HALF_EVEN
,IEEE 754R默认。
public static final MathContext DECIMAL128
MathContext
对象与精度设置匹配的IEEE 754R decimal128格式,34位数字,和舍入模式
HALF_EVEN
,IEEE 754R默认。
public MathContext(int setPrecision)
MathContext
与指定的精度和
HALF_UP
舍入模式。
setPrecision
-非负
int
精度设置。
IllegalArgumentException
-如果
setPrecision
参数小于零。
public MathContext(int setPrecision, RoundingMode setRoundingMode)
MathContext
和舍入模式。
setPrecision
-非负
int
精度设置。
setRoundingMode
的舍入模式使用。
IllegalArgumentException
-如果
setPrecision
参数小于零。
NullPointerException
如果舍入模式的说法是
null
public MathContext(String val)
MathContext
从字符串。字符串必须以相同的格式,由
toString()
法生产。
一个IllegalArgumentException
是如果字符串精确截面范围外扔(< 0
)或字符串不是由toString()
方法创建的格式。
val
-被解析的字符串
IllegalArgumentException
-如果精度部分超出范围或格式不正确
NullPointerException
-如果参数是
null
public int getPrecision()
precision
设置。此值总是非负的。
int
是价值的
precision
设置
public RoundingMode getRoundingMode()
RoundingMode.CEILING
,
RoundingMode.DOWN
,
RoundingMode.FLOOR
,
RoundingMode.HALF_DOWN
,
RoundingMode.HALF_EVEN
,
RoundingMode.HALF_UP
,
RoundingMode.UNNECESSARY
,或
RoundingMode.UP
。
RoundingMode
对象是价值的
roundingMode
设置
public boolean equals(Object x)
MathContext
与平等的规定
Object
比较。
equals
方法重写,继承类
Object
x
-
Object
这
MathContext
是比较。
true
当且仅当指定的
Object
是
MathContext
对象具有完全相同的设置为该对象
Object.hashCode()
,
HashMap
public int hashCode()
MathContext
哈希代码。
hashCode
方法重写,继承类
Object
MathContext
哈希代码
Object.equals(java.lang.Object)
,
System.identityHashCode(java.lang.Object)
public String toString()
MathContext
返回的字符串表示形式。返回的
String
代表的
MathContext
对象设置为两个空格分隔的单词(分离单个空格字符,
'\u0020',且没有前导或尾随空格),如下:
"precision="
,紧接着的值的精度设置为数字的字符串作为如果由Integer.toString
方法生成。"roundingMode="
,紧接着的一句话roundingMode
设定值。这句话将作为在RoundingMode
列举相应的公共常量的名称相同。例如:
精度= 9 roundingmode = half_up附加词都可以附加在未来
toString
结果如果更多的属性添加到该类。
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.