다음을 통해 공유


BigDecimal Class

Definition

The BigDecimal class implements immutable arbitrary-precision decimal numbers.

[Android.Runtime.Register("android/icu/math/BigDecimal", ApiSince=24, DoNotGenerateAcw=true)]
public class BigDecimal : Java.Lang.Number, IDisposable, Java.Interop.IJavaPeerable, Java.Lang.IComparable
[<Android.Runtime.Register("android/icu/math/BigDecimal", ApiSince=24, DoNotGenerateAcw=true)>]
type BigDecimal = class
    inherit Number
    interface ISerializable
    interface IJavaObject
    interface IDisposable
    interface IJavaPeerable
    interface IComparable
Inheritance
BigDecimal
Attributes
Implements

Remarks

The BigDecimal class implements immutable arbitrary-precision decimal numbers. The methods of the BigDecimal class provide operations for fixed and floating point arithmetic, comparison, format conversions, and hashing.

As the numbers are decimal, there is an exact correspondence between an instance of a BigDecimal object and its String representation; the BigDecimal class provides direct conversions to and from String and character array (char[]) objects, as well as conversions to and from the Java primitive types (which may not be exact) and BigInteger.

In the descriptions of constructors and methods in this documentation, the value of a BigDecimal number object is shown as the result of invoking the toString() method on the object. The internal representation of a decimal number is neither defined nor exposed, and is not permitted to affect the result of any operation.

The floating point arithmetic provided by this class is defined by the ANSI X3.274-1996 standard, and is also documented at http://www2.hursley.ibm.com/decimal<br> [This URL will change.]<h3>Operator methods</h3>

Operations on BigDecimal numbers are controlled by a MathContext object, which provides the context (precision and other information) for the operation. Methods that can take a MathContext parameter implement the standard arithmetic operators for BigDecimal objects and are known as operator methods. The default settings provided by the constant MathContext#DEFAULT (digits=9, form=SCIENTIFIC, lostDigits=false, roundingMode=ROUND_HALF_UP) perform general-purpose floating point arithmetic to nine digits of precision. The MathContext parameter must not be null.

Each operator method also has a version provided which does not take a MathContext parameter. For this version of each method, the context settings used are digits=0, form=PLAIN, lostDigits=false, roundingMode=ROUND_HALF_UP; these settings perform fixed point arithmetic with unlimited precision, as defined for the original BigDecimal class in Java 1.1 and Java 1.2.

For monadic operators, only the optional MathContext parameter is present; the operation acts upon the current object.

For dyadic operators, a BigDecimal parameter is always present; it must not be null. The operation acts with the current object being the left-hand operand and the BigDecimal parameter being the right-hand operand.

For example, adding two BigDecimal objects referred to by the names award and extra could be written as any of:

award.add(extra) <br>award.add(extra, MathContext.DEFAULT) <br>award.add(extra, acontext)

(where acontext is a MathContext object), which would return a BigDecimal object whose value is the result of adding award and extra under the appropriate context settings.

When a BigDecimal operator method is used, a set of rules define what the result will be (and, by implication, how the result would be represented as a character string). These rules are defined in the BigDecimal arithmetic documentation (see the URL above), but in summary: <ul> <li>Results are normally calculated with up to some maximum number of significant digits. For example, if the MathContext parameter for an operation were MathContext.DEFAULT then the result would be rounded to 9 digits; the division of 2 by 3 would then result in 0.666666667. <br> You can change the default of 9 significant digits by providing the method with a suitable MathContext object. This lets you calculate using as many digits as you need -- thousands, if necessary. Fixed point (scaled) arithmetic is indicated by using a digits setting of 0 (or omitting the MathContext parameter). <br> Similarly, you can change the algorithm used for rounding from the default "classic" algorithm. <li> In standard arithmetic (that is, when the form setting is not PLAIN), a zero result is always expressed as the single digit '0' (that is, with no sign, decimal point, or exponent part). <li> Except for the division and power operators in standard arithmetic, trailing zeros are preserved (this is in contrast to binary floating point operations and most electronic calculators, which lose the information about trailing zeros in the fractional part of results). <br> So, for example:

new BigDecimal("2.40").add( new BigDecimal("2")) =&gt; "4.40" <br>new BigDecimal("2.40").subtract(new BigDecimal("2")) =&gt; "0.40" <br>new BigDecimal("2.40").multiply(new BigDecimal("2")) =&gt; "4.80" <br>new BigDecimal("2.40").divide( new BigDecimal("2"), def) =&gt; "1.2"

where the value on the right of the =&gt; would be the result of the operation, expressed as a String, and def (in this and following examples) refers to MathContext.DEFAULT ). This preservation of trailing zeros is desirable for most calculations (including financial calculations). If necessary, trailing zeros may be easily removed using division by 1. <li> In standard arithmetic, exponential form is used for a result depending on its value and the current setting of digits (the default is 9 digits). If the number of places needed before the decimal point exceeds the digits setting, or the absolute value of the number is less than 0.000001, then the number will be expressed in exponential notation; thus

new BigDecimal("1e+6").multiply(new BigDecimal("1e+6"), def)

results in 1E+12 instead of 1000000000000, and

new BigDecimal("1").divide(new BigDecimal("3E+10"), def)

results in 3.33333333E-11 instead of 0.0000000000333333333.

The form of the exponential notation (scientific or engineering) is determined by the form setting. </ul>

The names of methods in this class follow the conventions established by java.lang.Number, java.math.BigInteger, and java.math.BigDecimal in Java 1.1 and Java 1.2.

Java documentation for android.icu.math.BigDecimal.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Constructors

BigDecimal(BigDecimal)

Constructs a BigDecimal object from a java.math.BigDecimal.

BigDecimal(BigInteger, Int32)

Constructs a BigDecimal object from a BigInteger and a scale.

BigDecimal(BigInteger)

Constructs a BigDecimal object from a BigInteger, with scale 0.

BigDecimal(Char[], Int32, Int32)

Constructs a BigDecimal object from an array of characters.

BigDecimal(Char[])

Constructs a BigDecimal object from an array of characters.

BigDecimal(Double)

Constructs a BigDecimal object directly from a double.

BigDecimal(Int32)

Constructs a BigDecimal object directly from a int.

BigDecimal(Int64)

Constructs a BigDecimal object directly from a long.

BigDecimal(IntPtr, JniHandleOwnership)
BigDecimal(String)

Constructs a BigDecimal object from a String.

Fields

RoundCeiling
Obsolete.

Rounding mode to round to a more positive number.

RoundDown
Obsolete.

Rounding mode to round towards zero.

RoundFloor
Obsolete.

Rounding mode to round to a more negative number.

RoundHalfDown
Obsolete.

Rounding mode to round to nearest neighbor, where an equidistant value is rounded down.

RoundHalfEven
Obsolete.

Rounding mode to round to nearest neighbor, where an equidistant value is rounded to the nearest even neighbor.

RoundHalfUp
Obsolete.

Rounding mode to round to nearest neighbor, where an equidistant value is rounded up.

RoundUnnecessary
Obsolete.

Rounding mode to assert that no rounding is necessary.

RoundUp
Obsolete.

Rounding mode to round away from zero.

Properties

Class

Returns the runtime class of this Object.

(Inherited from Object)
Handle

The handle to the underlying Android instance.

(Inherited from Object)
JniIdentityHashCode (Inherited from Object)
JniPeerMembers
One

The BigDecimal constant "1".

PeerReference (Inherited from Object)
Ten

The BigDecimal constant "10".

ThresholdClass
ThresholdType
Zero

The BigDecimal constant "0".

Methods

Abs()

Returns a plain BigDecimal whose value is the absolute value of this BigDecimal.

Abs(MathContext)

Returns a BigDecimal whose value is the absolute value of this BigDecimal.

Add(BigDecimal, MathContext)

Returns a BigDecimal whose value is this+rhs.

Add(BigDecimal)

Returns a plain BigDecimal whose value is this+rhs, using fixed point arithmetic.

ByteValue()

Returns the value of the specified number as a byte.

(Inherited from Number)
ByteValueExact()

Converts this BigDecimal to a byte.

Clone()

Creates and returns a copy of this object.

(Inherited from Object)
CompareTo(BigDecimal, MathContext)

Compares this BigDecimal to another.

CompareTo(BigDecimal)

Compares this BigDecimal to another, using unlimited precision.

Dispose() (Inherited from Object)
Dispose(Boolean) (Inherited from Object)
Divide(BigDecimal, Int32, RoundOptions)

Returns a plain BigDecimal whose value is this/rhs, using fixed point arithmetic and a given scale and rounding mode.

Divide(BigDecimal, MathContext)

Returns a BigDecimal whose value is this/rhs.

Divide(BigDecimal, RoundOptions)

Returns a plain BigDecimal whose value is this/rhs, using fixed point arithmetic and a rounding mode.

Divide(BigDecimal)

Returns a plain BigDecimal whose value is this/rhs, using fixed point arithmetic.

DivideInteger(BigDecimal, MathContext)

Returns a BigDecimal whose value is the integer part of this/rhs.

DivideInteger(BigDecimal)

Returns a plain BigDecimal whose value is the integer part of this/rhs.

DoubleValue()

Converts this BigDecimal to a double.

Equals(Object)

Indicates whether some other object is "equal to" this one.

(Inherited from Object)
FloatValue()

Converts this BigDecimal to a float.

Format(Int32, Int32, Int32, Int32, Int32, RoundOptions)

Returns the String representation of this BigDecimal, modified by layout parameters and allowing exponential notation.

Format(Int32, Int32)

Returns the String representation of this BigDecimal, modified by layout parameters.

GetHashCode()

Returns a hash code value for the object.

(Inherited from Object)
IntValue()

Converts this BigDecimal to an int.

IntValueExact()

Converts this BigDecimal to an int.

JavaFinalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

(Inherited from Object)
LongValue()

Converts this BigDecimal to a long.

LongValueExact()

Converts this BigDecimal to a long.

Max(BigDecimal, MathContext)

Returns a BigDecimal whose value is the maximum of this and rhs.

Max(BigDecimal)

Returns a plain BigDecimal whose value is the maximum of this and rhs.

Min(BigDecimal, MathContext)

Returns a BigDecimal whose value is the minimum of this and rhs.

Min(BigDecimal)

Returns a plain BigDecimal whose value is the minimum of this and rhs.

MovePointLeft(Int32)

Returns a plain BigDecimal whose decimal point has been moved to the left by a specified number of positions.

MovePointRight(Int32)

Returns a plain BigDecimal whose decimal point has been moved to the right by a specified number of positions.

Multiply(BigDecimal, MathContext)

Returns a BigDecimal whose value is this*rhs.

Multiply(BigDecimal)

Returns a plain BigDecimal whose value is this*rhs, using fixed point arithmetic.

Negate()

Returns a plain BigDecimal whose value is -this.

Negate(MathContext)

Returns a BigDecimal whose value is -this.

Notify()

Wakes up a single thread that is waiting on this object's monitor.

(Inherited from Object)
NotifyAll()

Wakes up all threads that are waiting on this object's monitor.

(Inherited from Object)
Plus()

Returns a plain BigDecimal whose value is +this.

Plus(MathContext)

Returns a BigDecimal whose value is +this.

Pow(BigDecimal, MathContext)

Returns a BigDecimal whose value is this**rhs.

Pow(BigDecimal)

Returns a plain BigDecimal whose value is this**rhs, using fixed point arithmetic.

Remainder(BigDecimal, MathContext)

Returns a BigDecimal whose value is the remainder of this/rhs.

Remainder(BigDecimal)

Returns a plain BigDecimal whose value is the remainder of this/rhs, using fixed point arithmetic.

Scale()

Returns the scale of this BigDecimal.

SetHandle(IntPtr, JniHandleOwnership)

Sets the Handle property.

(Inherited from Object)
SetScale(Int32, RoundOptions)

Returns a plain BigDecimal with a given scale.

SetScale(Int32)

Returns a plain BigDecimal with a given scale.

ShortValue()

Returns the value of the specified number as a short.

(Inherited from Number)
ShortValueExact()

Converts this BigDecimal to a short.

Signum()

Returns the sign of this BigDecimal, as an int.

Subtract(BigDecimal, MathContext)

Returns a BigDecimal whose value is this-rhs.

Subtract(BigDecimal)

Returns a plain BigDecimal whose value is this-rhs, using fixed point arithmetic.

ToArray<T>() (Inherited from Object)
ToBigDecimal()

Converts this BigDecimal to a java.math.BigDecimal.

ToBigInteger()

Converts this BigDecimal to a java.math.BigInteger.

ToBigIntegerExact()

Converts this BigDecimal to a java.math.BigInteger.

ToCharArray()

Returns the BigDecimal as a character array.

ToString()

Returns a string representation of the object.

(Inherited from Object)
UnregisterFromRuntime() (Inherited from Object)
UnscaledValue()

Returns the number as a BigInteger after removing the scale.

ValueOf(Double)

Translates a double to a BigDecimal.

ValueOf(Int64, Int32)

Translates a long to a BigDecimal with a given scale.

ValueOf(Int64)

Translates a long to a BigDecimal.

Wait()

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>.

(Inherited from Object)
Wait(Int64, Int32)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)
Wait(Int64)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)

Explicit Interface Implementations

IComparable.CompareTo(Object)
IJavaPeerable.Disposed() (Inherited from Object)
IJavaPeerable.DisposeUnlessReferenced() (Inherited from Object)
IJavaPeerable.Finalized() (Inherited from Object)
IJavaPeerable.JniManagedPeerState (Inherited from Object)
IJavaPeerable.SetJniIdentityHashCode(Int32) (Inherited from Object)
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) (Inherited from Object)
IJavaPeerable.SetPeerReference(JniObjectReference) (Inherited from Object)

Extension Methods

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject)
GetJniTypeName(IJavaPeerable)

Gets the JNI name of the type of the instance self.

JavaAs<TResult>(IJavaPeerable)

Try to coerce self to type TResult, checking that the coercion is valid on the Java side.

TryJavaCast<TResult>(IJavaPeerable, TResult)

Try to coerce self to type TResult, checking that the coercion is valid on the Java side.

Applies to