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.