📄 bigdecimal.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd"><!--NewPage--><HTML><HEAD><!-- Generated by javadoc on Thu Apr 27 23:35:27 PDT 2000 --><TITLE>Java 2 Platform SE v1.3: Class BigDecimal</TITLE><LINK REL ="stylesheet" TYPE="text/css" HREF="../../stylesheet.css" TITLE="Style"></HEAD><BODY BGCOLOR="white"><!-- ========== START OF NAVBAR ========== --><A NAME="navbar_top"><!-- --></A><TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0"><TR><TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1"><A NAME="navbar_top_firstrow"><!-- --></A><TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3"> <TR ALIGN="center" VALIGN="top"> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD> <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="class-use/BigDecimal.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../index-files/index-1.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD> </TR></TABLE></TD><TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM><b>Java<sup><font size=-2>TM</font></sup> 2 Platform<br>Std. Ed. v1.3</b></EM></TD></TR><TR><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> PREV CLASS <A HREF="../../java/math/BigInteger.html"><B>NEXT CLASS</B></A></FONT></TD><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="../../index.html" TARGET="_top"><B>FRAMES</B></A> <A HREF="BigDecimal.html" TARGET="_top"><B>NO FRAMES</B></A></FONT></TD></TR><TR><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> SUMMARY: INNER | <A HREF="#field_summary">FIELD</A> | <A HREF="#constructor_summary">CONSTR</A> | <A HREF="#method_summary">METHOD</A></FONT></TD><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">DETAIL: <A HREF="#field_detail">FIELD</A> | <A HREF="#constructor_detail">CONSTR</A> | <A HREF="#method_detail">METHOD</A></FONT></TD></TR></TABLE><!-- =========== END OF NAVBAR =========== --><HR><!-- ======== START OF CLASS DATA ======== --><H2><FONT SIZE="-1">java.math</FONT><BR>Class BigDecimal</H2><PRE><A HREF="../../java/lang/Object.html">java.lang.Object</A> | +--<A HREF="../../java/lang/Number.html">java.lang.Number</A> | +--<B>java.math.BigDecimal</B></PRE><DL><DT><B>All Implemented Interfaces:</B> <DD><A HREF="../../java/lang/Comparable.html">Comparable</A>, <A HREF="../../java/io/Serializable.html">Serializable</A></DD></DL><HR><DL><DT>public class <B>BigDecimal</B><DT>extends <A HREF="../../java/lang/Number.html">Number</A><DT>implements <A HREF="../../java/lang/Comparable.html">Comparable</A></DL><P>Immutable, arbitrary-precision signed decimal numbers. A BigDecimal consists of an arbitrary precision integer <i>unscaled value</i> and a non-negative 32-bit integer <i>scale</i>, which represents the number of digits to the right of the decimal point. The number represented by the BigDecimal is <tt>(unscaledValue/10<sup>scale</sup>)</tt>. BigDecimal provides operations for basic arithmetic, scale manipulation, comparison, hashing, and format conversion. <p> The BigDecimal class gives its user complete control over rounding behavior, forcing the user to explicitly specify a rounding behavior for operations capable of discarding precision (<tt>divide</tt> and <tt>setScale</tt>). Eight <em>rounding modes</em> are provided for this purpose. <p> Two types of operations are provided for manipulating the scale of a BigDecimal: scaling/rounding operations and decimal point motion operations. Scaling/rounding operations (<tt>SetScale</tt>) return a BigDecimal whose value is approximately (or exactly) equal to that of the operand, but whose scale is the specified value; that is, they increase or decrease the precision of the number with minimal effect on its value. Decimal point motion operations (<tt>movePointLeft</tt> and <tt>movePointRight</tt>) return a BigDecimal created from the operand by moving the decimal point a specified distance in the specified direction; that is, they change a number's value without affecting its precision. <p> For the sake of brevity and clarity, pseudo-code is used throughout the descriptions of BigDecimal methods. The pseudo-code expression <tt>(i + j)</tt> is shorthand for "a BigDecimal whose value is that of the BigDecimal <tt>i</tt> plus that of the BigDecimal <tt>j</tt>." The pseudo-code expression <tt>(i == j)</tt> is shorthand for "<tt>true</tt> if and only if the BigDecimal <tt>i</tt> represents the same value as the the BigDecimal <tt>j</tt>." Other pseudo-code expressions are interpreted similarly. <p> Note: care should be exercised if BigDecimals are to be used as keys in a SortedMap or elements in a SortedSet, as BigDecimal's <i>natural ordering</i> is <i>inconsistent with equals</i>. See Comparable, SortedMap or SortedSet for more information.<P><DL><DT><B>See Also: </B><DD><A HREF="../../java/math/BigInteger.html"><CODE>BigInteger</CODE></A>, <A HREF="../../java/util/SortedMap.html"><CODE>SortedMap</CODE></A>, <A HREF="../../java/util/SortedSet.html"><CODE>SortedSet</CODE></A>, <A HREF="../../serialized-form.html#java.math.BigDecimal">Serialized Form</A></DL><HR><P><!-- ======== INNER CLASS SUMMARY ======== --><!-- =========== FIELD SUMMARY =========== --><A NAME="field_summary"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TD COLSPAN=2><FONT SIZE="+2"><B>Field Summary</B></FONT></TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>static int</CODE></FONT></TD><TD><CODE><B><A HREF="../../java/math/BigDecimal.html#ROUND_CEILING">ROUND_CEILING</A></B></CODE><BR> Rounding mode to round towards positive infinity.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>static int</CODE></FONT></TD><TD><CODE><B><A HREF="../../java/math/BigDecimal.html#ROUND_DOWN">ROUND_DOWN</A></B></CODE><BR> Rounding mode to round towards zero.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>static int</CODE></FONT></TD><TD><CODE><B><A HREF="../../java/math/BigDecimal.html#ROUND_FLOOR">ROUND_FLOOR</A></B></CODE><BR> Rounding mode to round towards negative infinity.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>static int</CODE></FONT></TD><TD><CODE><B><A HREF="../../java/math/BigDecimal.html#ROUND_HALF_DOWN">ROUND_HALF_DOWN</A></B></CODE><BR> Rounding mode to round towards "nearest neighbor" unless both neighbors are equidistant, in which case round down.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>static int</CODE></FONT></TD><TD><CODE><B><A HREF="../../java/math/BigDecimal.html#ROUND_HALF_EVEN">ROUND_HALF_EVEN</A></B></CODE><BR> Rounding mode to round towards the "nearest neighbor" unless both neighbors are equidistant, in which case, round towards the even neighbor.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>static int</CODE></FONT></TD><TD><CODE><B><A HREF="../../java/math/BigDecimal.html#ROUND_HALF_UP">ROUND_HALF_UP</A></B></CODE><BR> Rounding mode to round towards "nearest neighbor" unless both neighbors are equidistant, in which case round up.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>static int</CODE></FONT></TD><TD><CODE><B><A HREF="../../java/math/BigDecimal.html#ROUND_UNNECESSARY">ROUND_UNNECESSARY</A></B></CODE><BR> Rounding mode to assert that the requested operation has an exact result, hence no rounding is necessary.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>static int</CODE></FONT></TD><TD><CODE><B><A HREF="../../java/math/BigDecimal.html#ROUND_UP">ROUND_UP</A></B></CODE><BR> Rounding mode to round away from zero.</TD></TR></TABLE> <!-- ======== CONSTRUCTOR SUMMARY ======== --><A NAME="constructor_summary"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TD COLSPAN=2><FONT SIZE="+2"><B>Constructor Summary</B></FONT></TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="../../java/math/BigDecimal.html#BigDecimal(java.math.BigInteger)">BigDecimal</A></B>(<A HREF="../../java/math/BigInteger.html">BigInteger</A> val)</CODE><BR> Translates a BigInteger into a BigDecimal.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="../../java/math/BigDecimal.html#BigDecimal(java.math.BigInteger, int)">BigDecimal</A></B>(<A HREF="../../java/math/BigInteger.html">BigInteger</A> unscaledVal, int scale)</CODE><BR> Translates a BigInteger unscaled value and an int scale into a BigDecimal.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="../../java/math/BigDecimal.html#BigDecimal(double)">BigDecimal</A></B>(double val)</CODE><BR> Translates a double into a BigDecimal.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="../../java/math/BigDecimal.html#BigDecimal(java.lang.String)">BigDecimal</A></B>(<A HREF="../../java/lang/String.html">String</A> val)</CODE><BR> Translates the String representation of a BigDecmal into a BigDecimal.</TD></TR></TABLE> <!-- ========== METHOD SUMMARY =========== --><A NAME="method_summary"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TD COLSPAN=2><FONT SIZE="+2"><B>Method Summary</B></FONT></TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> <A HREF="../../java/math/BigDecimal.html">BigDecimal</A></CODE></FONT></TD><TD><CODE><B><A HREF="../../java/math/BigDecimal.html#abs()">abs</A></B>()</CODE><BR> Returns a BigDecimal whose value is the absolute value of this BigDecimal, and whose scale is <tt>this.scale()</tt>.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> <A HREF="../../java/math/BigDecimal.html">BigDecimal</A></CODE></FONT></TD><TD><CODE><B><A HREF="../../java/math/BigDecimal.html#add(java.math.BigDecimal)">add</A></B>(<A HREF="../../java/math/BigDecimal.html">BigDecimal</A> val)</CODE><BR> Returns a BigDecimal whose value is <tt>(this + val)</tt>, and whose scale is <tt>max(this.scale(), val.scale())</tt>.</TD></TR>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -