- Java.math 包補充
- Java.math - 列舉
- Java.math - 討論
Java.math.MathContext 類
介紹
java.math.MathContext 類提供不可變物件,這些物件封裝了上下文設定並描述了數值運算子的某些規則,例如 BigDecimal 類實現的那些運算子。
與基數無關的設定:
精度 (precision) - 用於運算的數字位數;結果將四捨五入到此精度。
舍入模式 (roundingMode) - 一個 RoundingMode 物件,指定用於舍入的演算法。
類宣告
以下是 java.math.MathContext 類的宣告:
public final class MathContext
extends Object
implements Serializable
欄位
以下是 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 物件,其設定具有無限精度算術所需的值。
類建構函式
| 序號 | 建構函式 & 描述 |
|---|---|
| 1 | MathContext(int setPrecision) 此建構函式建立一個具有指定精度和 HALF_UP 舍入模式的新 MathContext。 |
| 2 | MathContext(int setPrecision, RoundingMode setRoundingMode) 此建構函式建立一個具有指定精度和舍入模式的新 MathContext。 |
| 3 | MathContext(String val) 此建構函式從字串建立一個新的 MathContext。 |
類方法
| 序號 | 方法 & 描述 |
|---|---|
| 1 | boolean equals(Object x)
此方法比較此 MathContext 與指定的物件是否相等。 |
| 2 | int getPrecision()
此方法返回精度設定。 |
| 3 | RoundingMode getRoundingMode()
此方法返回 roundingMode 設定。 |
| 4 | int hashCode()
此方法返回此 MathContext 的雜湊碼。 |
| 5 | String toString()
此方法返回此 MathContext 的字串表示形式。 |