forked from JavaDevTeam/notes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjava-math-MathContext.java
More file actions
28 lines (21 loc) · 735 Bytes
/
java-math-MathContext.java
File metadata and controls
28 lines (21 loc) · 735 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
------------------------
MathContext |
------------------------
# 主要的作用是处理运算过程中的精度问题
# 静态变量
MathContext UNLIMITED = new MathContext(0, RoundingMode.HALF_UP)
* 不限制长度, 使用四舍五入的方式来舍入小数
MathContext DECIMAL32 = new MathContext(7, RoundingMode.HALF_EVEN)
MathContext DECIMAL64 = new MathContext(16, RoundingMode.HALF_EVEN)
MathContext DECIMAL128 = new MathContext(34, RoundingMode.HALF_EVEN)
# 构造方法
MathContext(int setPrecision)
MathContext(int setPrecision,RoundingMode setRoundingMode)
MathContext(String val)
setPrecision
* 精度,一共最长最少长度(包含小数)
setRoundingMode
* 舍入模式
# 实例方法
int getPrecision()
RoundingMode getRoundingMode()