目录
All Implemented Interfaces所有已实现接口
所在包:java.math.BigDecimal
All Implemented Interfaces(所有实现接口):
public class BigDecimal
extends Number
implements Comparable<BigDecimal>
BigDecimal
consists of an arbitrary precision integer unscaled value and a 32-bit integer scale.BigDecimal
is therefore (unscaledValue × 10-scale).不可变的,任意精度带符号的十进制数。
BigDecimal由一个任意精度的整数无标度值和一个32位的整数标度组成。
如果是0或正数,刻度是小数点右边的位数。
如果是负数,则该数的未标度值乘以10的该标度的否定次方。
因此,BigDecimal表示的数字的值为(unscaledValue × 10-scale)。
The BigDecimal
class provides operations for arithmetic, scale manipulation, rounding, comparison, hashing, and format conversion.
The toString()
method provides a canonical representation of a BigDecimal
.
BigDecimal类提供了用于算术、缩放操作、舍入、比较、哈希和格式转换的操作。
toString()方法提供了BigDecimal的规范表示。
The BigDecimal
class gives its user complete control over rounding behavior.
If no rounding mode is specified and the exact result cannot be represented, an exception is thrown;
otherwise, calculations can be carried out to a chosen precision and rounding mode by supplying an appropriate MathContext
object to the operation.
In either case, eight rounding modes are provided for the control of rounding.
Using the integer fields in this class (such as ROUND_HALF_UP
) to represent rounding mode is largely obsolete;
the enumeration values of the RoundingMode
enum
, (such as RoundingMode.HALF_UP
) should be used instead.
BigDecimal类为其用户提供了对舍入行为的完全控制。
如果没有指定舍入模式,并且无法表示准确的结果,则抛出异常;
否则,可以通过向操作提供适当的MathContext对象,以选择的精度和舍入模式执行计算。
在这两种情况下,都提供了8种舍入模式来控制舍入。
使用该类中的整数字段(如ROUND_HALF_UP)来表示舍入模式在很大程度上是过时的;
应该使用RoundingMode enum的枚举值(例如RoundingMode. half_up)。
When a MathContext
object is supplied with a precision setting of 0 (for example, MathContext.UNLIMITED
), arithmetic operations are exact, as are the arithmetic methods which take no MathContext
object.
(This is the only behavior that was supported in releases prior to 5.)
As a corollary of computing the exact result, the rounding mode setting of a MathContext
object with a precision setting of 0 is not used and thus irrelevant.
In the case of divide, the exact quotient could have an infinitely long decimal expansion;
for example, 1 divided by 3.
If the quotient has a nonterminating decimal expansion and the operation is specified to return an exact result, an ArithmeticException
is thrown.
Otherwise, the exact result of the division is returned, as done for other operations.
当MathContext对象的精度设置为0(例如MathContext. unlimited)时,算术操作是精确的,不接受MathContext对象的算术方法也是如此。
(这是5之前的版本中唯一支持的行为。)
作为计算精确结果的一个推论,不使用精度设置为0的MathContext对象的舍入模式设置,因此不相关。
在除法的情况下,精确的商可以有无限长的小数展开;
例如,1除以3。
如果商数有一个不终止的小数展开,并且指定该操作来返回一个精确的结果,则会引发一个算术异常。
否则,将返回除法的准确结果,就像对其他操作所做的那样。
When the precision setting is not 0, the rules of BigDecimal
arithmetic are broadly compatible with selected modes of operation of the arithmetic defined in ANSI X3.274-1996 and ANSI X3.274-1996/AM 1-2000 (section 7.4).
Unlike those standards, BigDecimal
includes many rounding modes, which were mandatory for division in BigDecimal
releases prior to 5.
Any conflicts between these ANSI standards and the BigDecimal
specification are resolved in favor of BigDecimal
.
当精度设置不为0时,BigDecimal算法的规则与ANSI X3.274-1996和ANSI X3.274-1996/AM 1-2000(第7.4节)中定义的算法的选定操作模式广泛兼容。
与这些标准不同的是,BigDecimal包含许多舍入模式,在5之前的BigDecimal版本中必须使用这些模式进行除法。
这些ANSI标准和BigDecimal规范之间的任何冲突都可以使用BigDecimal解决。
Since the same numerical value can have different representations (with different scales), the rules of arithmetic and rounding must specify both the numerical result and the scale used in the result's representation.
In general the rounding modes and precision setting determine how operations return results with a limited number of digits when the exact result has more digits (perhaps infinitely many in the case of division) than the number of digits returned.
First, the total number of digits to return is specified by the MathContext
's precision
setting; this determines the result's precision.
The digit count starts from the leftmost nonzero digit of the exact result.
The rounding mode determines how any discarded trailing digits affect the returned result.
由于相同的数值可以有不同的表示法(具有不同的刻度),算术规则和舍入规则必须同时指定数值结果和结果表示法中使用的刻度。
通常,四舍五入模式和精度设置决定了当实际结果的位数(在除法的情况下可能是无限多)大于返回的位数时,运算如何返回有限位数的结果。
首先,要返回的数字总数由MathContext的精度设置指定;这决定了结果的精度。
数字计数从精确结果的最左边的非零位开始。
舍入模式确定任何丢弃的尾随数字如何影响返回的结果。
For all arithmetic operators , the operation is carried out as though an exact intermediate result were first calculated and then rounded to the number of digits specified by the precision setting (if necessary), using the selected rounding mode.
If the exact result is not returned, some digit positions of the exact result are discarded.
When rounding increases the magnitude of the returned result, it is possible for a new digit position to be created by a carry propagating to a leading "9" digit.
For example, rounding the value 999.9 to three digits rounding up would be numerically equal to one thousand, represented as 100×101.
In such cases, the new "1" is the leading digit position of the returned result.
对于所有算术运算符,执行该操作时,如同首先计算一个精确的中间结果,然后使用所选的舍入模式四舍五入到精度设置指定的位数(如果需要)。
如果没有返回确切的结果,则丢弃确切结果的一些数字位置。
当四舍五入增加返回结果的大小时,可以通过将进位传播到前导“9”位来创建新的数字位置。
例如,将999.9的值四舍五入为三位数,在数字上就等于1000,表示为100×101。
在这种情况下,新的“1”是返回结果的前位数位置。
Besides a logical exact result, each arithmetic operation has a preferred scale for representing a result.
The preferred scale for each operation is listed in the table below.
除了逻辑精确的结果之外,每个算术运算都有一个表示结果的首选比例。
下表列出了每个操作的首选比例。
算术运算结果的首选标度
Operation 操作 | Preferred Scale of Result 优选结果量表 |
---|---|
Add | max(addend.scale(), augend.scale()) |
Subtract | max(minuend.scale(), subtrahend.scale()) |
Multiply | multiplier.scale() + multiplicand.scale() |
Divide | dividend.scale() - divisor.scale() |
These scales are the ones used by the methods which return exact arithmetic results;
except that an exact divide may have to use a larger scale since the exact result may have more digits.
For example, 1/32
is 0.03125
.
这些标度是用于返回精确算术结果的方法的标度;
除了精确的除法可能需要使用更大的刻度,因为精确的结果可能有更多的数字。
例如,1/32是0.03125。
Before rounding, the scale of the logical exact intermediate result is the preferred scale for that operation.
If the exact numerical result cannot be represented in precision
digits, rounding selects the set of digits to return and the scale of the result is reduced from the scale of the intermediate result to the least scale which can represent the precision
digits actually returned.
If the exact result can be represented with at most precision
digits, the representation of the result with the scale closest to the preferred scale is returned.
In particular, an exactly representable quotient may be represented in fewer than precision
digits by removing trailing zeros and decreasing the scale.
For example, rounding to three digits using the floor rounding mode,
在舍入之前,逻辑精确中间结果的刻度是该操作的首选刻度。
如果无法用精度数字表示精确的数值结果,则舍入选择要返回的一组数字,并将结果的比例从中间结果的比例减少到能够表示实际返回的精度数字的最小比例。
如果精确的结果可以用最精确的数字表示,则返回最接近首选刻度的结果的表示。
特别地,一个精确可表示的商数可以通过去掉尾随的零和减小比例来用小于精度的数字表示。
例如,舍入到三位数使用舍入模式,19/100 = 0.19 // integer=19, scale=2
but21/110 =
0.190 // integer=190, scale=3
Note that for add, subtract, and multiply, the reduction in scale will equal the number of digit positions of the exact result which are discarded.
If the rounding causes a carry propagation to create a new high-order digit position, an additional digit of the result is discarded than when no new digit position is created.
请注意,对于加法、减法和乘法,比例的减少将等于被丢弃的精确结果的数字位置的数量。
如果四舍五入导致进位传播创建一个新的高阶数字位置,则与没有创建新数字位置时相比,结果的一个额外数字将被丢弃。
Other methods may have slightly different rounding semantics.
For example,
the result of the pow
method using the specified
algorithm can occasionally differ from the rounded mathematical result by
more than one unit in the last place, one ulp.
其他方法可能具有略微不同的舍入语义。
例如,使用指定算法的pow方法的结果有时可能与四舍五入的数学结果相差一个以上的单元,即一个ulp。
Two types of operations are provided for manipulating the scale of a
BigDecimal
: scaling/rounding operations and decimal point motion
operations.
Scaling/rounding operations (setScale
and round
)
return a BigDecimal
whose value is approximately (or exactly) equal
to that of the operand, but whose scale or precision is the specified value;
that is, they increase or decrease the precision of the stored number with minimal effect on its value.
Decimal point motion operations (movePointLeft
and movePointRight
)
return a BigDecimal
created from the operand by moving the decimal
point a specified distance in the specified direction.
为操作BigDecimal的规模提供了两种类型的操作:缩放/舍入操作和小数点移动操作。
缩放/舍入操作(setScale和round)返回一个BigDecimal,其值近似(或确切)等于操作数的值,但其比例或精度是指定的值;
也就是说,它们增加或减少了存储数的精度,但对其值的影响很小。
小数点移动操作(movePointLeft和movePointRight)通过在指定的方向上移动小数点指定的距离,返回从操作数创建的BigDecimal。
For the sake of brevity and clarity, pseudo-code is used throughout the
descriptions of BigDecimal
methods.
The pseudo-code expression
(i + j)
is shorthand for "a BigDecimal
whose value is
that of the BigDecimal
i
added to that of the
BigDecimal
j
."
The pseudo-code expression (i ==
j)
is shorthand for "true
if and only if the
BigDecimal
i
represents the same value as the
BigDecimal
j
."
Other pseudo-code expressions are interpreted similarly.
Square brackets are used to represent the particular
BigInteger
and scale pair defining a BigDecimal
value;
for example [19, 2] is the BigDecimal
numerically equal to 0.19
having a scale of 2.
为了简洁和清晰,在BigDecimal方法的所有描述中都使用了伪代码。
伪代码表达式(i + j)是“BigDecimal的值是我添加到BigDecimal j中的BigDecimal的值”的缩写。
伪代码表达式(i == j)是“当且仅当BigDecimal i表示与BigDecimal j相同的值时为真”的缩写。
其他伪代码表达式的解释也类似。
方括号用于表示定义BigDecimal值的特定BigInteger和scale对;例如[19,2]是BigDecimal在数字上等于0.19,刻度为2。
Note: care should be exercised if BigDecimal
objects are used as
keys in a SortedMap
or elements in
a SortedSet
since
BigDecimal
's natural ordering is inconsistent with
equals.
See Comparable
, SortedMap
or SortedSet
for more
information.
注意:如果在SortedMap中使用BigDecimal对象作为键,或者在SortedSet中使用元素,应该小心,因为BigDecimal的自然顺序与equals不一致。
有关更多信息,请参见Comparable、SortedMap或SortedSet。
All methods and constructors for this class throw
NullPointerException
when passed a null
object
reference for any input parameter.
当为任何输入参数传递空对象引用时,该类的所有方法和构造函数都会抛出NullPointerException。
- See Also:
BigInteger
,MathContext
,RoundingMode
,SortedMap
,SortedSet
, Serialized Form
Field Summary(字段汇总)
Modifier and Type 修饰符和类型 |
Field and Description 字段和描述 |
---|---|
static BigDecimal |
ONE
The value 1, with a scale of 0.
值为1,刻度为0。
|
static int |
ROUND_CEILING
Rounding mode to round towards positive infinity.
四舍五入模式向正无穷四舍五入。
|
static int |
ROUND_DOWN
Rounding mode to round towards zero.
四舍五入模式向零进行四舍五入。
|
static int |
ROUND_FLOOR
Rounding mode to round towards negative infinity.
四舍五入模式向负无穷四舍五入。
|
static int |
ROUND_HALF_DOWN
Rounding mode to round towards "nearest neighbor" unless both neighbors are equidistant, in which case round down.
四舍五入模式向“最近的邻居”四舍五入,除非两个邻居的距离相等,在这种情况下四舍五入。
|
static int |
ROUND_HALF_EVEN
Rounding mode to round towards the "nearest neighbor" unless both neighbors are equidistant, in which case, round towards the even neighbor.
舍入方式向“最近的邻居”四舍五入,除非两个邻居的距离相等,在这种情况下,向偶数邻居四舍五入。
|
|
ROUND_HALF_UP
Rounding mode to round towards "nearest neighbor" unless both neighbors are equidistant, in which case round up.
四舍五入模式向“最近的邻居”四舍五入,除非两个邻居的距离相等,在这种情况下四舍五入。
|
static int |
ROUND_UNNECESSARY
Rounding mode to assert that the requested operation has an exact result, hence no rounding is necessary.
舍入模式,以断言请求的操作具有精确的结果,因此不需要进行舍入。
|
static int |
ROUND_UP
Rounding mode to round away from zero.
舍入模式从0开始四舍五入。
|
static BigDecimal |
TEN
The value 10, with a scale of 0.
值为1,刻度为0。
|
static BigDecimal |
ZERO
The value 0, with a scale of 0.
值为1,刻度为0。
|
Constructor Summary(构造函数的总结)
Constructor and Description 构造函数和描述 |
---|
BigDecimal(BigInteger val)
Translates a
BigInteger into a BigDecimal .将一个BigInteger转换为BigDecimal。
|
BigDecimal(BigInteger unscaledVal, int scale)
Translates a
BigInteger unscaled value and an int scale into a BigDecimal .将BigInteger未缩放值和int缩放转换为BigDecimal。
|
BigDecimal(BigInteger unscaledVal, int scale, MathContext mc)
Translates a
BigInteger unscaled value and an int scale into a BigDecimal , with rounding according to the context settings.将BigInteger未缩放值和int缩放转换为BigDecimal,并根据上下文设置进行舍入。
|
BigDecimal(BigInteger val, MathContext mc)
Translates a
BigInteger into a BigDecimal rounding according to the context settings.根据上下文设置将BigInteger转换为BigDecimal舍入。
|
BigDecimal(char[] in)
Translates a character array representation of a
BigDecimal into a BigDecimal , accepting the same sequence of characters as the BigDecimal(String) constructor.将BigDecimal的字符数组表示形式转换为BigDecimal,接受与BigDecimal(字符串)构造函数相同的字符序列。
|
BigDecimal(char[] in, int offset, int len)
Translates a character array representation of a
BigDecimal into a BigDecimal , accepting the same sequence of characters as the BigDecimal(String) constructor, while allowing a sub-array to be specified.将BigDecimal的字符数组表示形式转换为BigDecimal,接受与BigDecimal(String)构造函数相同的字符序列,同时允许指定子数组。
|
BigDecimal(char[] in, int offset, int len, MathContext mc)
Translates a character array representation of a
BigDecimal into a BigDecimal , accepting the same sequence of characters as the BigDecimal(String) constructor, while allowing a sub-array to be specified and with rounding according to the context settings.将BigDecimal的字符数组表示形式转换为BigDecimal,接受与BigDecimal(String)构造函数相同的字符序列,同时允许指定子数组,并根据上下文设置进行舍入。
|
BigDecimal(char[] in, MathContext mc)
Translates a character array representation of a
BigDecimal into a BigDecimal , accepting the same sequence of characters as the BigDecimal(String) constructor and with rounding according to the context settings.将BigDecimal的字符数组表示形式转换为BigDecimal,接受与BigDecimal(字符串)构造函数相同的字符序列,并根据上下文设置进行舍入。
|
BigDecimal(double val)
Translates a
double into a BigDecimal which is the exact decimal representation of the double 's binary floating-point value.将double转换为BigDecimal,后者是double的二进制浮点值的精确十进制表示形式。
|
BigDecimal(double val, MathContext mc)
Translates a
double into a BigDecimal , with rounding according to the context settings.将double转换为BigDecimal,并根据上下文设置进行舍入。
|
BigDecimal(int val)
Translates an
int into a BigDecimal .将int转换成BigDecimal。
|
BigDecimal(int val, MathContext mc)
Translates an
int into a BigDecimal , with rounding according to the context settings.将int转换为BigDecimal,并根据上下文设置进行舍入。
|
BigDecimal(long val)
Translates a
long into a BigDecimal .把long转换成BigDecimal。
|
BigDecimal(long val, MathContext mc)
Translates a
long into a BigDecimal , with rounding according to the context settings.将long转换为BigDecimal,并根据上下文设置进行舍入。
|
BigDecimal(String val)
Translates the string representation of a
BigDecimal into a BigDecimal .将BigDecimal的字符串表示形式转换为BigDecimal。
|
BigDecimal(String val, MathContext mc)
Translates the string representation of a
BigDecimal into a BigDecimal , accepting the same strings as the BigDecimal(String) constructor, with rounding according to the context settings.将BigDecimal的字符串表示形式转换为BigDecimal,接受与BigDecimal(string)构造函数相同的字符串,并根据上下文设置进行舍入。
|
Method Summary方法总结
Modifier and Type | Method and Description |
---|---|
BigDecimal |
abs()
Returns a
BigDecimal whose value is the absolute value of this BigDecimal , and whose scale is this.scale() .返回一个BigDecimal,其值是这个BigDecimal的绝对值,其刻度是this.scale()。
|
BigDecimal |
abs(MathContext mc)
Returns a
BigDecimal whose value is the absolute value of this BigDecimal , with rounding according to the context settings.返回一个BigDecimal,其值是这个BigDecimal的绝对值,根据上下文设置进行舍入。
|
BigDecimal |
add(BigDecimal augend)
Returns a
BigDecimal whose value is (this + augend) , and whose scale is max(this.scale(), augend.scale()) .返回一个BigDecimal,其值为(this + augend),其刻度为max(this.scale(), augen .scale())。
|
BigDecimal |
add(BigDecimal augend, MathContext mc)
Returns a
BigDecimal whose value is (this + augend) , with rounding according to the context settings.返回一个BigDecimal,其值为(this + augend),并根据上下文设置进行舍入。
|
byte |
byteValueExact()
Converts this
BigDecimal to a byte , checking for lost information.将此BigDecimal转换为字节,检查丢失的信息。
|
int |
compareTo(BigDecimal val)
Compares this
BigDecimal with the specified BigDecimal .将这个BigDecimal与指定的BigDecimal进行比较。
|
BigDecimal |
divide(BigDecimal divisor)
Returns a
BigDecimal whose value is (this / divisor) , and whose preferred scale is (this.scale() - divisor.scale()) ; if the exact quotient cannot be represented (because it has a non-terminating decimal expansion) an ArithmeticException is thrown.返回一个BigDecimal,其值为(this /除数),其首选的刻度为(this.scale() - divisor ()); |
BigDecimal |
divide(BigDecimal divisor, int roundingMode)
Returns a
BigDecimal whose value is (this / divisor) , and whose scale is this.scale() .返回一个BigDecimal,其值为(this /除数),其刻度为this.scale()。
|
BigDecimal |
divide(BigDecimal divisor, int scale, int roundingMode)
Returns a
BigDecimal whose value is (this / divisor) , and whose scale is as specified.返回一个BigDecimal,它的值是(this /除数),并且它的比例是指定的。
|
BigDecimal |
divide(BigDecimal divisor, int scale, RoundingMode roundingMode)
Returns a
BigDecimal whose value is (this / divisor) , and whose scale is as specified.返回一个BigDecimal,它的值是(this /除数),并且它的比例是指定的。
|
BigDecimal |
divide(BigDecimal divisor, MathContext mc)
Returns a
BigDecimal whose value is (this / divisor) , with rounding according to the context settings.返回一个BigDecimal,其值为(this /除数),并根据上下文设置进行舍入。
|
BigDecimal |
divide(BigDecimal divisor, RoundingMode roundingMode)
Returns a
BigDecimal whose value is (this / divisor) , and whose scale is this.scale() .返回一个BigDecimal,其值为(this /除数),其刻度为this.scale()。
|
BigDecimal[] |
divideAndRemainder(BigDecimal divisor)
Returns a two-element
BigDecimal array containing the result of divideToIntegralValue followed by the result of remainder on the two operands.返回一个双元素BigDecimal数组,该数组包含两个操作数上的除法tointegralvalue的结果和余数的结果。
|
BigDecimal[] |
divideAndRemainder(BigDecimal divisor, MathContext mc)
Returns a two-element
BigDecimal array containing the result of divideToIntegralValue followed by the result of remainder on the two operands calculated with rounding according to the context settings.返回一个包含两个元素的BigDecimal数组,其中包含divideToIntegralValue的结果以及根据上下文设置进行舍入计算的两个操作数上的余数的结果。
|
BigDecimal |
divideToIntegralValue(BigDecimal divisor)
Returns a
BigDecimal whose value is the integer part of the quotient (this / divisor) rounded down.返回一个BigDecimal,其值是四舍五入后的商(这个/除数)的整数部分。
|
BigDecimal |
divideToIntegralValue(BigDecimal divisor, MathContext mc)
Returns a
BigDecimal whose value is the integer part of (this / divisor) .返回一个BigDecimal,其值是(这个/除数)的整数部分。
|
double |
doubleValue()
Converts this
BigDecimal to a double .将这个BigDecimal转换为double。
|
boolean |
equals(Object x)
Compares this
BigDecimal with the specified Object for equality.将这个BigDecimal与指定的对象进行比较以获得相等性。
|
float |
floatValue()
Converts this
BigDecimal to a float .将此BigDecimal转换为浮点数。
|
int |
hashCode()
Returns the hash code for this
BigDecimal .返回这个BigDecimal的散列代码。
|
int |
intValue()
Converts this
BigDecimal to an int .将此BigDecimal转换为int。
|
int |
intValueExact()
Converts this
BigDecimal to an int , checking for lost information.将此BigDecimal转换为int,检查丢失的信息。
|
long |
longValue()
Converts this
BigDecimal to a long .将这个BigDecimal转换为long。
|
long |
longValueExact()
Converts this
BigDecimal to a long , checking for lost information.将此BigDecimal转换为long,以检查丢失的信息。
|
BigDecimal |
max(BigDecimal val)
Returns the maximum of this
BigDecimal and val .返回此BigDecimal和val的最大值。
|
BigDecimal |
min(BigDecimal val)
Returns the minimum of this
BigDecimal and val .返回此BigDecimal和val的最小值。
|
BigDecimal |
movePointLeft(int n)
Returns a
BigDecimal which is equivalent to this one with the decimal point moved n places to the left.返回一个BigDecimal,它等价于这个小数点左移n位的BigDecimal。
|
BigDecimal |
movePointRight(int n)
Returns a
BigDecimal which is equivalent to this one with the decimal point moved n places to the right.返回一个BigDecimal,它等价于这个小数点右移n位的BigDecimal。
|
BigDecimal |
multiply(BigDecimal multiplicand)
Returns a
BigDecimal whose value is (this × multiplicand), and whose scale is (this.scale() + multiplicand.scale()) .返回一个BigDecimal,它的值是(this×multiplicand),它的scale是(this.scale() + multiplicand.scale())。
|
BigDecimal |
multiply(BigDecimal multiplicand, MathContext mc)
Returns a
BigDecimal whose value is (this × multiplicand), with rounding according to the context settings.返回一个BigDecimal,其值为(this×multiplicand),根据上下文设置进行舍入。
|
BigDecimal |
negate()
Returns a
BigDecimal whose value is (-this) , and whose scale is this.scale() .返回一个BigDecimal,其值为(-this),其刻度为this.scale()。
|
BigDecimal |
negate(MathContext mc)
Returns a
BigDecimal whose value is (-this) , with rounding according to the context settings.返回一个BigDecimal,其值为(-this),根据上下文设置进行舍入。
|
BigDecimal |
plus()
Returns a
BigDecimal whose value is (+this) , and whose scale is this.scale() .返回一个BigDecimal,其值为(+this),其刻度为this.scale()。
|
BigDecimal |
plus(MathContext mc)
Returns a
BigDecimal whose value is (+this) , with rounding according to the context settings.返回一个BigDecimal,其值为(+this),并根据上下文设置进行舍入。
|
BigDecimal |
pow(int n)
Returns a
BigDecimal whose value is (thisn), The power is computed exactly, to unlimited precision.返回一个BigDecimal,其值为(thisn),精确计算幂次,达到无限的精度。
|
BigDecimal |
pow(int n, MathContext mc)
Returns a
BigDecimal whose value is (thisn).返回一个BigDecimal,其值为(thisn)。
|
int |
precision()
Returns the precision of this
BigDecimal .返回这个BigDecimal的精度。
|
BigDecimal |
remainder(BigDecimal divisor)
Returns a
BigDecimal whose value is (this % divisor) .返回一个BigDecimal,其值为(这个%除数)。
|
BigDecimal |
remainder(BigDecimal divisor, MathContext mc)
Returns a
BigDecimal whose value is (this % divisor) , with rounding according to the context settings.返回一个BigDecimal,其值为(此%除数),并根据上下文设置进行舍入。
|
BigDecimal |
round(MathContext mc)
Returns a
BigDecimal rounded according to the MathContext settings.根据MathContext设置返回一个BigDecimal。
|
int |
scale()
Returns the scale of this
BigDecimal .返回这个BigDecimal的比例。
|
BigDecimal |
scaleByPowerOfTen(int n)
Returns a BigDecimal whose numerical value is equal to (
this * 10n).返回一个BigDecimal,其数值等于(this * 10n)。
|
BigDecimal |
setScale(int newScale)
Returns a
BigDecimal whose scale is the specified value, and whose value is numerically equal to this BigDecimal 's.返回一个BigDecimal,其刻度是指定的值,其值在数值上等于这个BigDecimal的值。
|
BigDecimal |
setScale(int newScale, int roundingMode)
Returns a
BigDecimal whose scale is the specified value, and whose unscaled value is determined by multiplying or dividing this BigDecimal 's unscaled value by the appropriate power of ten to maintain its overall value.返回一个BigDecimal,其刻度是指定的值,其未缩放值是通过将该BigDecimal的未缩放值乘以或除以适当的10次方来确定的,以保持其整体值。
|
BigDecimal |
setScale(int newScale, RoundingMode roundingMode)
Returns a
BigDecimal whose scale is the specified value, and whose unscaled value is determined by multiplying or dividing this BigDecimal 's unscaled value by the appropriate power of ten to maintain its overall value.返回一个BigDecimal,其刻度是指定的值,其未缩放值是通过将该BigDecimal的未缩放值乘以或除以适当的10次方来确定的,以保持其整体值。
|
short |
shortValueExact()
Converts this
BigDecimal to a short , checking for lost information.将此BigDecimal转换为短格式,以检查丢失的信息。
|
int |
signum()
Returns the signum function of this
BigDecimal .返回这个BigDecimal的sgn函数。
|
BigDecimal |
stripTrailingZeros()
Returns a
BigDecimal which is numerically equal to this one but with any trailing zeros removed from the representation.返回一个BigDecimal,该BigDecimal在数值上与这个BigDecimal相等,但是在表示中去掉了任何尾随的零。
|
BigDecimal |
subtract(BigDecimal subtrahend)
Returns a
BigDecimal whose value is (this - subtrahend) , and whose scale is max(this.scale(), subtrahend.scale()) .返回一个BigDecimal,它的值是(this - subtration),它的scale是max(this.scale(), subtraend .scale())。
|
BigDecimal |
subtract(BigDecimal subtrahend, MathContext mc)
Returns a
BigDecimal whose value is (this - subtrahend) , with rounding according to the context settings.返回一个BigDecimal,其值为(this - subtra),并根据上下文设置进行舍入。
|
BigInteger |
toBigInteger()
Converts this
BigDecimal to a BigInteger .将此BigDecimal转换为BigInteger。
|
BigInteger |
toBigIntegerExact()
Converts this
BigDecimal to a BigInteger , checking for lost information.将此BigDecimal转换为BigInteger,检查丢失的信息。
|
String |
toEngineeringString()
Returns a string representation of this
BigDecimal , using engineering notation if an exponent is needed.返回此BigDecimal的字符串表示形式,如果需要指数,则使用工程符号。
|
String |
toPlainString()
Returns a string representation of this
BigDecimal without an exponent field.返回这个不带指数字段的BigDecimal的字符串表示形式。
|
String |
toString()
Returns the string representation of this
BigDecimal , using scientific notation if an exponent is needed.返回此BigDecimal的字符串表示形式,如果需要指数,则使用科学符号。
|
BigDecimal |
ulp()
Returns the size of an ulp, a unit in the last place, of this
BigDecimal .返回一个ulp的大小,也就是这个BigDecimal的最后一位。
|
BigInteger |
unscaledValue()
Returns a
BigInteger whose value is the unscaled value of this BigDecimal .返回一个BigInteger,其值是这个BigDecimal的未缩放值。
|
static BigDecimal |
valueOf(double val)
Translates a
double into a BigDecimal , using the double 's canonical string representation provided by the Double.toString(double) method.使用double . tostring (double)方法提供的double的规范字符串表示形式,将double转换为BigDecimal。
|
static BigDecimal |
valueOf(long val)
Translates a
long value into a BigDecimal with a scale of zero.将长值转换为具有0刻度的BigDecimal。
|
static BigDecimal |
valueOf(long unscaledVal, int scale)
Translates a
long unscaled value and an int scale into a BigDecimal .将一个长未缩放值和一个整型刻度转换为BigDecimal。
|
Methods inherited from class java.lang.Number(方法继承自java.lang.Number类)
Methods inherited from class java.lang.Object(方法继承自java.lang.Object类)
clone, finalize, getClass, notify, notifyAll, wait, wait, wait