目录

Java.math - MathContext

介绍 (Introduction)

java.math.MathContext类提供了不可变对象,它们封装了上下文设置,并描述了数值运算符的某些规则,例如BigDecimal类实现的规则。

与基础无关的设置是 -

  • precision - 操作使用的位数; 结果四舍五入到此精度。

  • roundingMode - 一个RoundingMode对象,指定用于舍入的算法。

类声明

以下是java.math.MathContext类的声明 -

public final class MathContext
   extends Object
      implements Serializable

字段 (Field)

以下是java.math.MathContext类的字段 -

  • 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对象,其设置具有无限精度算术所需的值。

类构造函数

Sr.No. 构造函数和描述
1

MathContext(int setPrecision)

此构造函数构造具有指定精度的新MathContext和HALF_UP舍入模式。

2

MathContext(int setPrecision, RoundingMode setRoundingMode)

此构造函数构造具有指定精度和舍入模式的新MathContext。

3

MathContext(String val)

此构造函数从字符串构造新的MathContext。

类方法

Sr.No. 方法和描述
1 boolean equals(Object x)

此方法将此MathContext与指定的Object进行比较以获得相等性。

2 int getPrecision()

此方法返回精度设置。

3 RoundingMode getRoundingMode()

此方法返回roundingMode设置。

4 int hashCode()

此方法返回此MathContext的哈希码。

5 String toString()

此方法返回此MathContext的字符串表示形式。

↑回到顶部↑
WIKI教程 @2018