Java Doc for BigDecimal.java in  » 6.0-JDK-Modules » j2me » java » math » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » j2me » java.math 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   java.lang.Number
      java.math.BigDecimal

BigDecimal
public class BigDecimal extends Number implements Comparable(Code)
Immutable, arbitrary-precision signed decimal numbers. A BigDecimal consists of an arbitrary precision integer unscaled value and a non-negative 32-bit integer scale, which represents the number of digits to the right of the decimal point. The number represented by the BigDecimal is (unscaledValue/10scale). BigDecimal provides operations for basic arithmetic, scale manipulation, comparison, hashing, and format conversion.

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 ( BigDecimal.divide(BigDecimal,int) , BigDecimal.divide(BigDecimal,int,int) , and BigDecimal.setScale ). Eight rounding modes are provided for this purpose.

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) 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 ( BigDecimal.movePointLeft and BigDecimal.movePointRight ) 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.

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 plus 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 the BigDecimal j." Other pseudo-code expressions are interpreted similarly.

Note: care should be exercised if BigDecimals are to be used as keys in a java.util.SortedMap or elements in a java.util.SortedSet , as BigDecimal's natural ordering is inconsistent with equals. See Comparable , java.util.SortedMap or java.util.SortedSet for more information.

All methods and constructors for this class throw NullPointerException when passed a null object reference for any input parameter.
See Also:   BigInteger
See Also:   java.util.SortedMap
See Also:   java.util.SortedSet
version:
   1.33, 08/19/02
author:
   Josh Bloch



Field Summary
final public static  intROUND_CEILING
     Rounding mode to round towards positive infinity.
final public static  intROUND_DOWN
     Rounding mode to round towards zero.
final public static  intROUND_FLOOR
     Rounding mode to round towards negative infinity.
final public static  intROUND_HALF_DOWN
     Rounding mode to round towards "nearest neighbor" unless both neighbors are equidistant, in which case round down.
final public static  intROUND_HALF_EVEN
     Rounding mode to round towards the "nearest neighbor" unless both neighbors are equidistant, in which case, round towards the even neighbor.
final public static  intROUND_HALF_UP
     Rounding mode to round towards "nearest neighbor" unless both neighbors are equidistant, in which case round up. Behaves as for ROUND_UP if the discarded fraction is >= .5; otherwise, behaves as for ROUND_DOWN.
final public static  intROUND_UNNECESSARY
     Rounding mode to assert that the requested operation has an exact result, hence no rounding is necessary.
final public static  intROUND_UP
     Rounding mode to round away from zero.

Constructor Summary
public  BigDecimal(String val)
     Translates the String representation of a BigDecimal into a BigDecimal.
public  BigDecimal(double val)
     Translates a double into a BigDecimal.
public  BigDecimal(BigInteger val)
     Translates a BigInteger into a BigDecimal.
public  BigDecimal(BigInteger unscaledVal, int scale)
     Translates a BigInteger unscaled value and an int scale into a BigDecimal.

Method Summary
public  BigDecimalabs()
     Returns a BigDecimal whose value is the absolute value of this BigDecimal, and whose scale is this.scale().
public  BigDecimaladd(BigDecimal val)
     Returns a BigDecimal whose value is (this + val), and whose scale is max(this.scale(), val.scale()).
Parameters:
  val - value to be added to this BigDecimal.
public  intcompareTo(BigDecimal val)
     Compares this BigDecimal with the specified BigDecimal.
public  intcompareTo(Object o)
     Compares this BigDecimal with the specified Object.
public  BigDecimaldivide(BigDecimal val, int scale, int roundingMode)
     Returns a BigDecimal whose value is (this / val), and whose scale is as specified.
public  BigDecimaldivide(BigDecimal val, int roundingMode)
     Returns a BigDecimal whose value is (this / val), and whose scale is this.scale().
public  doubledoubleValue()
     Converts this BigDecimal to a double.
public  booleanequals(Object x)
     Compares this BigDecimal with the specified Object for equality.
public  floatfloatValue()
     Converts this BigDecimal to a float.
public  inthashCode()
     Returns the hash code for this BigDecimal.
public  intintValue()
     Converts this BigDecimal to an int.
public  longlongValue()
     Converts this BigDecimal to a long.
public  BigDecimalmax(BigDecimal val)
     Returns the maximum of this BigDecimal and val.
Parameters:
  val - value with which the maximum is to be computed.
public  BigDecimalmin(BigDecimal val)
     Returns the minimum of this BigDecimal and val.
Parameters:
  val - value with which the minimum is to be computed.
public  BigDecimalmovePointLeft(int n)
     Returns a BigDecimal which is equivalent to this one with the decimal point moved n places to the left.
public  BigDecimalmovePointRight(int n)
     Moves the decimal point the specified number of places to the right. If this BigDecimal's scale is >= n, the call merely subtracts n from the scale; otherwise, it sets the scale to zero, and multiplies the integer value by 10(n - this.scale).
public  BigDecimalmultiply(BigDecimal val)
     Returns a BigDecimal whose value is (this * val), and whose scale is (this.scale() + val.scale()).
Parameters:
  val - value to be multiplied by this BigDecimal.
public  BigDecimalnegate()
     Returns a BigDecimal whose value is (-this), and whose scale is this.scale().
public  intscale()
     Returns the scale of this BigDecimal.
public  BigDecimalsetScale(int scale, 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.
public  BigDecimalsetScale(int scale)
     Returns a BigDecimal whose scale is the specified value, and whose value is numerically equal to this BigDecimal's.
public  intsignum()
     Returns the signum function of this BigDecimal.
public  BigDecimalsubtract(BigDecimal val)
     Returns a BigDecimal whose value is (this - val), and whose scale is max(this.scale(), val.scale()).
Parameters:
  val - value to be subtracted from this BigDecimal.
public  BigIntegertoBigInteger()
     Converts this BigDecimal to a BigInteger.
public  StringtoString()
     Returns the string representation of this BigDecimal.
public  BigIntegerunscaledValue()
     Returns a BigInteger whose value is the unscaled value of this BigDecimal.
public static  BigDecimalvalueOf(long unscaledVal, int scale)
     Translates a long unscaled value and an int scale into a BigDecimal.
public static  BigDecimalvalueOf(long val)
     Translates a long value into a BigDecimal with a scale of zero.

Field Detail
ROUND_CEILING
final public static int ROUND_CEILING(Code)
Rounding mode to round towards positive infinity. If the BigDecimal is positive, behaves as for ROUND_UP; if negative, behaves as for ROUND_DOWN. Note that this rounding mode never decreases the calculated value.



ROUND_DOWN
final public static int ROUND_DOWN(Code)
Rounding mode to round towards zero. Never increments the digit prior to a discarded fraction (i.e., truncates). Note that this rounding mode never increases the magnitude of the calculated value.



ROUND_FLOOR
final public static int ROUND_FLOOR(Code)
Rounding mode to round towards negative infinity. If the BigDecimal is positive, behave as for ROUND_DOWN; if negative, behave as for ROUND_UP. Note that this rounding mode never increases the calculated value.



ROUND_HALF_DOWN
final public static int ROUND_HALF_DOWN(Code)
Rounding mode to round towards "nearest neighbor" unless both neighbors are equidistant, in which case round down. Behaves as for ROUND_UP if the discarded fraction is > .5; otherwise, behaves as for ROUND_DOWN.



ROUND_HALF_EVEN
final public static int ROUND_HALF_EVEN(Code)
Rounding mode to round towards the "nearest neighbor" unless both neighbors are equidistant, in which case, round towards the even neighbor. Behaves as for ROUND_HALF_UP if the digit to the left of the discarded fraction is odd; behaves as for ROUND_HALF_DOWN if it's even. Note that this is the rounding mode that minimizes cumulative error when applied repeatedly over a sequence of calculations.



ROUND_HALF_UP
final public static int ROUND_HALF_UP(Code)
Rounding mode to round towards "nearest neighbor" unless both neighbors are equidistant, in which case round up. Behaves as for ROUND_UP if the discarded fraction is >= .5; otherwise, behaves as for ROUND_DOWN. Note that this is the rounding mode that most of us were taught in grade school.



ROUND_UNNECESSARY
final public static int ROUND_UNNECESSARY(Code)
Rounding mode to assert that the requested operation has an exact result, hence no rounding is necessary. If this rounding mode is specified on an operation that yields an inexact result, an ArithmeticException is thrown.



ROUND_UP
final public static int ROUND_UP(Code)
Rounding mode to round away from zero. Always increments the digit prior to a non-zero discarded fraction. Note that this rounding mode never decreases the magnitude of the calculated value.




Constructor Detail
BigDecimal
public BigDecimal(String val)(Code)
Translates the String representation of a BigDecimal into a BigDecimal. The String representation consists of an optional sign, '+' ('\u002B') or '-' ('\u002D'), followed by a sequence of zero or more decimal digits ("the integer"), optionally followed by a fraction, optionally followed by an exponent.

The fraction consists of of a decimal point followed by zero or more decimal digits. The string must contain at least one digit in either the integer or the fraction. The number formed by the sign, the integer and the fraction is referred to as the significand.

The exponent consists of the character 'e' ('\u0075') or 'E' ('\u0045') followed by one or more decimal digits. The value of the exponent must lie between - Integer.MAX_VALUE ( Integer.MIN_VALUE +1) and Integer.MAX_VALUE , inclusive.

More formally, the strings this constructor accepts are described by the following grammar:

BigDecimalString:
Signopt Significand Exponentopt

Sign:
+
-

Significand:
IntegerPart . FractionPartopt
. FractionPart
IntegerPart

IntegerPart:
Digits

FractionPart:
Digits

Exponent:
ExponentIndicator SignedInteger

ExponentIndicator:
e
E

SignedInteger:
Signopt Digits

Digits:
Digit
Digits Digit

Digit:
any character for which Character.isDigit returns true, including 0, 1, 2 ...

The scale of the returned BigDecimal will be the number of digits in the fraction, or zero if the string contains no decimal point, subject to adjustment for any exponent: If the string contains an exponent, the exponent is subtracted from the scale. If the resulting scale is negative, the scale of the returned BigDecimal is zero and the unscaled value is multiplied by the appropriate power of ten so that, in every case, the resulting BigDecimal is equal to significand × 10exponent. (If in the future this specification is amended to permit negative scales, the final step of zeroing the scale and adjusting the unscaled value will be eliminated.)

The character-to-digit mapping is provided by java.lang.Character.digit set to convert to radix 10. The String may not contain any extraneous characters (whitespace, for example).

Note: For values other float and double NaN and ±Infinity, this constructor is compatible with the values returned by Float.toString and Double.toString . This is generally the preferred way to convert a float or double into a BigDecimal, as it doesn't suffer from the unpredictability of the BigDecimal.BigDecimal(double) constructor.

Note: the optional leading plus sign and trailing exponent were added in release 1.3.
Parameters:
  val - String representation of BigDecimal.
throws:
  NumberFormatException - val is not a valid representationof a BigDecimal.




BigDecimal
public BigDecimal(double val)(Code)
Translates a double into a BigDecimal. The scale of the BigDecimal is the smallest value such that (10scale * val) is an integer.

Note: the results of this constructor can be somewhat unpredictable. One might assume that new BigDecimal(.1) is exactly equal to .1, but it is actually equal to .1000000000000000055511151231257827021181583404541015625. This is so because .1 cannot be represented exactly as a double (or, for that matter, as a binary fraction of any finite length). Thus, the long value that is being passed in to the constructor is not exactly equal to .1, appearances notwithstanding.

The (String) constructor, on the other hand, is perfectly predictable: new BigDecimal(".1") is exactly equal to .1, as one would expect. Therefore, it is generally recommended that the (String) constructor be used in preference to this one.
Parameters:
  val - double value to be converted to BigDecimal.
throws:
  NumberFormatException - val if val isinfinite or NaN.




BigDecimal
public BigDecimal(BigInteger val)(Code)
Translates a BigInteger into a BigDecimal. The scale of the BigDecimal is zero.
Parameters:
  val - BigInteger value to be converted to BigDecimal.



BigDecimal
public BigDecimal(BigInteger unscaledVal, int scale)(Code)
Translates a BigInteger unscaled value and an int scale into a BigDecimal. The value of the BigDecimal is (unscaledVal/10scale).
Parameters:
  unscaledVal - unscaled value of the BigDecimal.
Parameters:
  scale - scale of the BigDecimal.
throws:
  NumberFormatException - scale is negative




Method Detail
abs
public BigDecimal abs()(Code)
Returns a BigDecimal whose value is the absolute value of this BigDecimal, and whose scale is this.scale(). abs(this)



add
public BigDecimal add(BigDecimal val)(Code)
Returns a BigDecimal whose value is (this + val), and whose scale is max(this.scale(), val.scale()).
Parameters:
  val - value to be added to this BigDecimal. this + val



compareTo
public int compareTo(BigDecimal val)(Code)
Compares this BigDecimal with the specified BigDecimal. Two BigDecimals that are equal in value but have a different scale (like 2.0 and 2.00) are considered equal by this method. This method is provided in preference to individual methods for each of the six boolean comparison operators (<, ==, >, >=, !=, <=). The suggested idiom for performing these comparisons is: (x.compareTo(y) <op> 0), where <op> is one of the six comparison operators.
Parameters:
  val - BigDecimal to which this BigDecimal is to be compared. -1, 0 or 1 as this BigDecimal is numerically less than, equalto, or greater than val.



compareTo
public int compareTo(Object o)(Code)
Compares this BigDecimal with the specified Object. If the Object is a BigDecimal, this method behaves like BigDecimal.compareTo compareTo . Otherwise, it throws a ClassCastException (as BigDecimals are comparable only to other BigDecimals).
Parameters:
  o - Object to which this BigDecimal is to be compared. a negative number, zero, or a positive number as thisBigDecimal is numerically less than, equal to, or greaterthan o, which must be a BigDecimal.
throws:
  ClassCastException - o is not a BigDecimal.
See Also:   BigDecimal.compareTo(java.math.BigDecimal)
See Also:   Comparable
since:
   1.2



divide
public BigDecimal divide(BigDecimal val, int scale, int roundingMode)(Code)
Returns a BigDecimal whose value is (this / val), and whose scale is as specified. If rounding must be performed to generate a result with the specified scale, the specified rounding mode is applied.
Parameters:
  val - value by which this BigDecimal is to be divided.
Parameters:
  scale - scale of the BigDecimal quotient to be returned.
Parameters:
  roundingMode - rounding mode to apply. this / val
throws:
  ArithmeticException - val is zero, scale isnegative, or roundingMode==ROUND_UNNECESSARY andthe specified scale is insufficient to represent the resultof the division exactly.
throws:
  IllegalArgumentException - roundingMode does notrepresent a valid rounding mode.
See Also:   BigDecimal.ROUND_UP
See Also:   BigDecimal.ROUND_DOWN
See Also:   BigDecimal.ROUND_CEILING
See Also:   BigDecimal.ROUND_FLOOR
See Also:   BigDecimal.ROUND_HALF_UP
See Also:   BigDecimal.ROUND_HALF_DOWN
See Also:   BigDecimal.ROUND_HALF_EVEN
See Also:   BigDecimal.ROUND_UNNECESSARY



divide
public BigDecimal divide(BigDecimal val, int roundingMode)(Code)
Returns a BigDecimal whose value is (this / val), and whose scale is this.scale(). If rounding must be performed to generate a result with the given scale, the specified rounding mode is applied.
Parameters:
  val - value by which this BigDecimal is to be divided.
Parameters:
  roundingMode - rounding mode to apply. this / val
throws:
  ArithmeticException - val==0, orroundingMode==ROUND_UNNECESSARY andthis.scale() is insufficient to represent the resultof the division exactly.
throws:
  IllegalArgumentException - roundingMode does notrepresent a valid rounding mode.
See Also:   BigDecimal.ROUND_UP
See Also:   BigDecimal.ROUND_DOWN
See Also:   BigDecimal.ROUND_CEILING
See Also:   BigDecimal.ROUND_FLOOR
See Also:   BigDecimal.ROUND_HALF_UP
See Also:   BigDecimal.ROUND_HALF_DOWN
See Also:   BigDecimal.ROUND_HALF_EVEN
See Also:   BigDecimal.ROUND_UNNECESSARY



doubleValue
public double doubleValue()(Code)
Converts this BigDecimal to a double. This conversion is similar to the narrowing primitive conversion from double to float as defined in the Java Language Specification: if this BigDecimal has too great a magnitude represent as a double, it will be converted to Double.NEGATIVE_INFINITY or Double.POSITIVE_INFINITY as appropriate. Note that even when the return value is finite, this conversion can lose information about the precision of the BigDecimal value. this BigDecimal converted to a double.



equals
public boolean equals(Object x)(Code)
Compares this BigDecimal with the specified Object for equality. Unlike BigDecimal.compareTo compareTo , this method considers two BigDecimals equal only if they are equal in value and scale (thus 2.0 is not equal to 2.00 when compared by this method).
Parameters:
  x - Object to which this BigDecimal is to be compared. true if and only if the specified Object is aBigDecimal whose value and scale are equal to this BigDecimal's.
See Also:   BigDecimal.compareTo(java.math.BigDecimal)



floatValue
public float floatValue()(Code)
Converts this BigDecimal to a float. This conversion is similar to the narrowing primitive conversion from double to float defined in the Java Language Specification: if this BigDecimal has too great a magnitude to represent as a float, it will be converted to Float.NEGATIVE_INFINITY or Float.POSITIVE_INFINITY as appropriate. Note that even when the return value is finite, this conversion can lose information about the precision of the BigDecimal value. this BigDecimal converted to a float.



hashCode
public int hashCode()(Code)
Returns the hash code for this BigDecimal. Note that two BigDecimals that are numerically equal but differ in scale (like 2.0 and 2.00) will generally not have the same hash code. hash code for this BigDecimal.



intValue
public int intValue()(Code)
Converts this BigDecimal to an int. This conversion is analogous to a narrowing primitive conversion from double to short as defined in the Java Language Specification: any fractional part of this BigDecimal will be discarded, and if the resulting "BigInteger" is too big to fit in an int, only the low-order 32 bits are returned. Note that this conversion can lose information about the overall magnitude and precision of the BigDecimal value as well as return a result with the opposite sign. this BigDecimal converted to an int.



longValue
public long longValue()(Code)
Converts this BigDecimal to a long. This conversion is analogous to a narrowing primitive conversion from double to short as defined in the Java Language Specification: any fractional part of this BigDecimal will be discarded, and if the resulting "BigInteger" is too big to fit in a long, only the low-order 64 bits are returned. Note that this conversion can lose information about the overall magnitude and precision of the BigDecimal value as well as return a result with the opposite sign. this BigDecimal converted to an long.



max
public BigDecimal max(BigDecimal val)(Code)
Returns the maximum of this BigDecimal and val.
Parameters:
  val - value with which the maximum is to be computed. the BigDecimal whose value is the greater of this BigDecimaland val. If they are equal, as defined by theBigDecimal.compareTo compareTo method, either may be returned.
See Also:   BigDecimal.compareTo(java.math.BigDecimal)



min
public BigDecimal min(BigDecimal val)(Code)
Returns the minimum of this BigDecimal and val.
Parameters:
  val - value with which the minimum is to be computed. the BigDecimal whose value is the lesser of this BigDecimal and val. If they are equal, as defined by theBigDecimal.compareTo compareTo method, either may be returned.
See Also:   BigDecimal.compareTo(java.math.BigDecimal)



movePointLeft
public BigDecimal movePointLeft(int n)(Code)
Returns a BigDecimal which is equivalent to this one with the decimal point moved n places to the left. If n is non-negative, the call merely adds n to the scale. If n is negative, the call is equivalent to movePointRight(-n). (The BigDecimal returned by this call has value (this * 10-n) and scale max(this.scale()+n, 0).)
Parameters:
  n - number of places to move the decimal point to the left. a BigDecimal which is equivalent to this one with the decimalpoint moved n places to the left.



movePointRight
public BigDecimal movePointRight(int n)(Code)
Moves the decimal point the specified number of places to the right. If this BigDecimal's scale is >= n, the call merely subtracts n from the scale; otherwise, it sets the scale to zero, and multiplies the integer value by 10(n - this.scale). If n is negative, the call is equivalent to movePointLeft(-n). (The BigDecimal returned by this call has value (this * 10n) and scale max(this.scale()-n, 0).)
Parameters:
  n - number of places to move the decimal point to the right. a BigDecimal which is equivalent to this one with the decimalpoint moved n places to the right.



multiply
public BigDecimal multiply(BigDecimal val)(Code)
Returns a BigDecimal whose value is (this * val), and whose scale is (this.scale() + val.scale()).
Parameters:
  val - value to be multiplied by this BigDecimal. this * val



negate
public BigDecimal negate()(Code)
Returns a BigDecimal whose value is (-this), and whose scale is this.scale(). -this



scale
public int scale()(Code)
Returns the scale of this BigDecimal. (The scale is the number of digits to the right of the decimal point.) the scale of this BigDecimal.



setScale
public BigDecimal setScale(int scale, int roundingMode)(Code)
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. If the scale is reduced by the operation, the unscaled value must be divided (rather than multiplied), and the value may be changed; in this case, the specified rounding mode is applied to the division.

Note that since BigDecimal objects are immutable, calls of this method do not result in the original object being modified, contrary to the usual convention of having methods named setX mutate field X. Instead, setScale returns an object with the proper scale; the returned object may or may not be newly allocated.
Parameters:
  scale - scale of the BigDecimal value to be returned.
Parameters:
  roundingMode - The rounding mode to apply. a BigDecimal whose scale is the specified value, and whoseunscaled value is determined by multiplying or dividing thisBigDecimal's unscaled value by the appropriate power of ten tomaintain its overall value.
throws:
  ArithmeticException - scale is negative, orroundingMode==ROUND_UNNECESSARY and the specifiedscaling operation would require rounding.
throws:
  IllegalArgumentException - roundingMode does notrepresent a valid rounding mode.
See Also:   BigDecimal.ROUND_UP
See Also:   BigDecimal.ROUND_DOWN
See Also:   BigDecimal.ROUND_CEILING
See Also:   BigDecimal.ROUND_FLOOR
See Also:   BigDecimal.ROUND_HALF_UP
See Also:   BigDecimal.ROUND_HALF_DOWN
See Also:   BigDecimal.ROUND_HALF_EVEN
See Also:   BigDecimal.ROUND_UNNECESSARY




setScale
public BigDecimal setScale(int scale)(Code)
Returns a BigDecimal whose scale is the specified value, and whose value is numerically equal to this BigDecimal's. Throws an ArithmeticException if this is not possible. This call is typically used to increase the scale, in which case it is guaranteed that there exists a BigDecimal of the specified scale and the correct value. The call can also be used to reduce the scale if the caller knows that the BigDecimal has sufficiently many zeros at the end of its fractional part (i.e., factors of ten in its integer value) to allow for the rescaling without loss of precision.

This method returns the same result as the two argument version of setScale, but saves the caller the trouble of specifying a rounding mode in cases where it is irrelevant.

Note that since BigDecimal objects are immutable, calls of this method do not result in the original object being modified, contrary to the usual convention of having methods named setX mutate field X. Instead, setScale returns an object with the proper scale; the returned object may or may not be newly allocated.
Parameters:
  scale - scale of the BigDecimal value to be returned. a BigDecimal whose scale is the specified value, and whoseunscaled value is determined by multiplying or dividing thisBigDecimal's unscaled value by the appropriate power of ten tomaintain its overall value.
throws:
  ArithmeticException - scale is negative, orthe specified scaling operation would require rounding.
See Also:   BigDecimal.setScale(int,int)




signum
public int signum()(Code)
Returns the signum function of this BigDecimal. -1, 0 or 1 as the value of this BigDecimal is negative, zero orpositive.



subtract
public BigDecimal subtract(BigDecimal val)(Code)
Returns a BigDecimal whose value is (this - val), and whose scale is max(this.scale(), val.scale()).
Parameters:
  val - value to be subtracted from this BigDecimal. this - val



toBigInteger
public BigInteger toBigInteger()(Code)
Converts this BigDecimal to a BigInteger. This conversion is analogous to a narrowing primitive conversion from double to long as defined in the Java Language Specification: any fractional part of this BigDecimal will be discarded. Note that this conversion can lose information about the precision of the BigDecimal value. this BigDecimal converted to a BigInteger.



toString
public String toString()(Code)
Returns the string representation of this BigDecimal. The digit-to- character mapping provided by Character.forDigit is used. A leading minus sign is used to indicate sign, and the number of digits to the right of the decimal point is used to indicate scale. (This representation is compatible with the (String) constructor.) String representation of this BigDecimal.
See Also:   Character.forDigit
See Also:   BigDecimal.BigDecimal(java.lang.String)



unscaledValue
public BigInteger unscaledValue()(Code)
Returns a BigInteger whose value is the unscaled value of this BigDecimal. (Computes (this * 10this.scale()).) the unscaled value of this BigDecimal.
since:
   1.2



valueOf
public static BigDecimal valueOf(long unscaledVal, int scale)(Code)
Translates a long unscaled value and an int scale into a BigDecimal. This "static factory method" is provided in preference to a (long, int) constructor because it allows for reuse of frequently used BigDecimals.
Parameters:
  unscaledVal - unscaled value of the BigDecimal.
Parameters:
  scale - scale of the BigDecimal. a BigDecimal whose value is(unscaledVal/10scale).



valueOf
public static BigDecimal valueOf(long val)(Code)
Translates a long value into a BigDecimal with a scale of zero. This "static factory method" is provided in preference to a (long) constructor because it allows for reuse of frequently used BigDecimals.
Parameters:
  val - value of the BigDecimal. a BigDecimal whose value is val.



Methods inherited from java.lang.Number
public byte byteValue()(Code)(Java Doc)
abstract public double doubleValue()(Code)(Java Doc)
abstract public float floatValue()(Code)(Java Doc)
abstract public int intValue()(Code)(Java Doc)
abstract public long longValue()(Code)(Java Doc)
public short shortValue()(Code)(Java Doc)

Methods inherited from java.lang.Object
public boolean equals(Object obj)(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.