- java.lang.Object
-  
      - java.math.MathContext
 
-  
       - 实现的所有接口
-  
         Serializable
 
 public final class MathContext extends Object implements Serializable 不可变对象,它封装了描述数值运算符某些规则的上下文设置,例如BigDecimal类实现的规则 。与基础无关的设置是: -  precision:操作使用的位数; 结果四舍五入到此精度
-  roundingMode:RoundingMode对象,指定用于舍入的算法。
 - 从以下版本开始:
- 1.5
- 另请参见:
-  
         BigDecimal,RoundingMode, Serialized Form
 
-  
        
       -  
             字段汇总字段 变量和类型 字段 描述 static MathContextDECIMAL128MathContext对象,其精度设置与IEEE 754R Decimal128格式匹配,为34位,舍入模式为HALF_EVEN,即IEEE 754R默认值。static MathContextDECIMAL32MathContext对象,其精度设置与IEEE 754R Decimal32格式匹配,为7位数,舍入模式为HALF_EVEN,即IEEE 754R默认值。static MathContextDECIMAL64MathContext对象,其精度设置与IEEE 754R Decimal64格式匹配,16位数,舍入模式为HALF_EVEN,即IEEE 754R默认值。static MathContextUNLIMITEDMathContext对象,其设置具有无限精度算术所需的值。
 -  
             构造方法摘要构造方法 构造器 描述 MathContext(int setPrecision)构造具有指定精度的新MathContext和HALF_UP舍入模式。MathContext(int setPrecision, RoundingMode setRoundingMode)构造具有指定精度和舍入模式的新MathContext。MathContext(String val)从字符串构造一个新的MathContext。
 -  
             方法摘要所有方法 实例方法 具体的方法 变量和类型 方法 描述 booleanequals(Object x)将此MathContext与指定的Object进行相等性比较。intgetPrecision()返回precision设置。RoundingModegetRoundingMode()返回roundingMode设置。inthashCode()返回此MathContext的哈希码。StringtoString()返回此MathContext的字符串表示MathContext。
 
-  
             
-  
        
       -  
             字段详细信息-  UNLIMITEDpublic static final MathContext UNLIMITED MathContext对象,其设置具有无限精度算术所需的值。 设置值为:precision=0 roundingMode=HALF_UP
 -  DECIMAL32public static final MathContext DECIMAL32 MathContext对象,其精度设置与IEEE 754R Decimal32格式匹配,为7位数,舍入模式为HALF_EVEN,即IEEE 754R默认值。
 -  DECIMAL64public static final MathContext DECIMAL64 MathContext对象,其精度设置与IEEE 754R Decimal64格式匹配,16位,舍入模式为HALF_EVEN,即IEEE 754R默认值。
 -  DECIMAL128public static final MathContext DECIMAL128 MathContext对象,其精度设置与IEEE 754R Decimal128格式匹配,为34位,舍入模式为HALF_EVEN,即IEEE 754R默认值。
 
-  
 -  
             构造方法详细信息-  MathContextpublic MathContext(int setPrecision) 构造具有指定精度的新MathContext和HALF_UP舍入模式。- 参数
-  
              setPrecision- 非负int精度设置。
- 异常
-  
              IllegalArgumentException- 如果setPrecision参数小于零。
 
 -  MathContextpublic MathContext(int setPrecision, RoundingMode setRoundingMode)构造具有指定精度和舍入模式的新MathContext。- 参数
-  
              setPrecision- 非负int精度设置。
-  
              setRoundingMode- 要使用的舍入模式。
- 异常
-  
              IllegalArgumentException- 如果setPrecision参数小于零。
-  
              NullPointerException- 如果舍入模式参数为null
 
 -  MathContextpublic MathContext(String val) 从字符串构造一个新的MathContext。 该字符串的格式必须与toString()方法生成的格式相同。一个 IllegalArgumentException被抛出如果字符串的精度部分超出范围(< 0),或该字符串不是在由创建的格式toString()方法。- 参数
-  
              val- 要解析的字符串
- 异常
-  
              IllegalArgumentException- 如果精度部分超出范围或格式不正确
-  
              NullPointerException- 如果参数是null
 
 
-  
 -  
             方法详细信息-  getPrecisionpublic int getPrecision() 返回precision设置。 此值始终为非负值。- 结果
-  
              int这是precision设置的值
 
 -  getRoundingModepublic RoundingMode getRoundingMode() 返回roundingMode设置。 这将是一个RoundingMode.CEILING,RoundingMode.DOWN,RoundingMode.FLOOR,RoundingMode.HALF_DOWN,RoundingMode.HALF_EVEN,RoundingMode.HALF_UP,RoundingMode.UNNECESSARY,或RoundingMode.UP。- 结果
-  
              RoundingMode对象,它是roundingMode设置的值
 
 -  equalspublic boolean equals(Object x) 将此MathContext与指定的Object进行相等性比较。- 重写:
-  
              equals在类Object
- 参数
-  
              x-Object这个MathContext要比较。
- 结果
-  
              true当且仅当指定的Object是MathContext对象时,其设置与此对象完全相同
- 另请参见:
-  
              Object.hashCode(),HashMap
 
 -  hashCodepublic int hashCode() 返回此MathContext的哈希码。- 重写:
-  
              hashCode在类Object
- 结果
- 
               此 
              MathContext哈希码
- 另请参见:
-  
              Object.equals(java.lang.Object),System.identityHashCode(java.lang.Object)
 
 -  toStringpublic String toString() 返回此MathContext的字符串表示MathContext。 所述String返回表示的设置MathContext对象作为两个空格分隔单词(由单个空格字符,分离的'\u0020',并与无前导或尾随空格),如下所示:-  字符串"precision=",紧接着是精度设置的值,作为数字字符串,就好像由Integer.toString方法生成一样 。
-  字符串"roundingMode=",紧接着是roundingMode设置为单词的值。 该单词与RoundingMode枚举中相应公共常量的名称相同。
 例如: precision=9 roundingMode=HALF_UP如果将更多属性添加到此类,将来可能会在toString的结果中附加其他单词。
-  字符串
 
-  
 
-