Uses of Class
java.math.BigDecimal
Package
Description
Provides classes for performing arbitrary-precision integer
arithmetic (
BigInteger
) and arbitrary-precision decimal
arithmetic (BigDecimal
).Provides the API for accessing and processing data stored in a
data source (usually a relational database) using the
Java programming language.
Contains the collections framework, some internationalization support classes,
a service loader, properties, random number generation, string parsing
and scanning classes, base64 encoding and decoding, a bit array, and
several miscellaneous utility classes.
Provides the open data types and Open MBean descriptor classes.
Provides the API for server side data source access and processing from
the Java programming language.
Standard interfaces and base classes for JDBC
RowSet
implementations.Provides utility classes to allow serializable mappings between SQL types
and data types in the Java programming language.
Defines XML/Java Type Mappings.
-
Uses of BigDecimal in java.math
Modifier and TypeFieldDescriptionstatic BigDecimal
BigDecimal.ONE
The value 1, with a scale of 0.static BigDecimal
BigDecimal.TEN
The value 10, with a scale of 0.static BigDecimal
BigDecimal.ZERO
The value 0, with a scale of 0.Modifier and TypeMethodDescriptionBigDecimal.abs()
Returns aBigDecimal
whose value is the absolute value of thisBigDecimal
, and whose scale isthis.scale()
.BigDecimal.abs(MathContext mc)
Returns aBigDecimal
whose value is the absolute value of thisBigDecimal
, with rounding according to the context settings.BigDecimal.add(BigDecimal augend)
Returns aBigDecimal
whose value is(this + augend)
, and whose scale ismax(this.scale(), augend.scale())
.BigDecimal.add(BigDecimal augend, MathContext mc)
Returns aBigDecimal
whose value is(this + augend)
, with rounding according to the context settings.BigDecimal.divide(BigDecimal divisor)
Returns aBigDecimal
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) anArithmeticException
is thrown.BigDecimal.divide(BigDecimal divisor, int roundingMode)
Deprecated.BigDecimal.divide(BigDecimal divisor, int scale, int roundingMode)
Deprecated.The methoddivide(BigDecimal, int, RoundingMode)
should be used in preference to this legacy method.BigDecimal.divide(BigDecimal divisor, int scale, RoundingMode roundingMode)
Returns aBigDecimal
whose value is(this / divisor)
, and whose scale is as specified.BigDecimal.divide(BigDecimal divisor, MathContext mc)
Returns aBigDecimal
whose value is(this / divisor)
, with rounding according to the context settings.BigDecimal.divide(BigDecimal divisor, RoundingMode roundingMode)
Returns aBigDecimal
whose value is(this / divisor)
, and whose scale isthis.scale()
.BigDecimal.divideAndRemainder(BigDecimal divisor)
Returns a two-elementBigDecimal
array containing the result ofdivideToIntegralValue
followed by the result ofremainder
on the two operands.BigDecimal.divideAndRemainder(BigDecimal divisor, MathContext mc)
Returns a two-elementBigDecimal
array containing the result ofdivideToIntegralValue
followed by the result ofremainder
on the two operands calculated with rounding according to the context settings.BigDecimal.divideToIntegralValue(BigDecimal divisor)
Returns aBigDecimal
whose value is the integer part of the quotient(this / divisor)
rounded down.BigDecimal.divideToIntegralValue(BigDecimal divisor, MathContext mc)
Returns aBigDecimal
whose value is the integer part of(this / divisor)
.BigDecimal.max(BigDecimal val)
Returns the maximum of thisBigDecimal
andval
.BigDecimal.min(BigDecimal val)
Returns the minimum of thisBigDecimal
andval
.BigDecimal.movePointLeft(int n)
Returns aBigDecimal
which is equivalent to this one with the decimal point movedn
places to the left.BigDecimal.movePointRight(int n)
Returns aBigDecimal
which is equivalent to this one with the decimal point movedn
places to the right.BigDecimal.multiply(BigDecimal multiplicand)
Returns aBigDecimal
whose value is(this × multiplicand)
, and whose scale is(this.scale() + multiplicand.scale())
.BigDecimal.multiply(BigDecimal multiplicand, MathContext mc)
Returns aBigDecimal
whose value is(this × multiplicand)
, with rounding according to the context settings.BigDecimal.negate()
Returns aBigDecimal
whose value is(-this)
, and whose scale isthis.scale()
.BigDecimal.negate(MathContext mc)
Returns aBigDecimal
whose value is(-this)
, with rounding according to the context settings.BigDecimal.plus()
Returns aBigDecimal
whose value is(+this)
, and whose scale isthis.scale()
.BigDecimal.plus(MathContext mc)
Returns aBigDecimal
whose value is(+this)
, with rounding according to the context settings.BigDecimal.pow(int n)
Returns aBigDecimal
whose value is(thisn)
, The power is computed exactly, to unlimited precision.BigDecimal.pow(int n, MathContext mc)
Returns aBigDecimal
whose value is(thisn)
.BigDecimal.remainder(BigDecimal divisor)
Returns aBigDecimal
whose value is(this % divisor)
.BigDecimal.remainder(BigDecimal divisor, MathContext mc)
Returns aBigDecimal
whose value is(this % divisor)
, with rounding according to the context settings.BigDecimal.round(MathContext mc)
Returns aBigDecimal
rounded according to theMathContext
settings.BigDecimal.scaleByPowerOfTen(int n)
Returns a BigDecimal whose numerical value is equal to (this
* 10n).BigDecimal.setScale(int newScale)
Returns aBigDecimal
whose scale is the specified value, and whose value is numerically equal to thisBigDecimal
's.BigDecimal.setScale(int newScale, int roundingMode)
Deprecated.The methodsetScale(int, RoundingMode)
should be used in preference to this legacy method.BigDecimal.setScale(int newScale, RoundingMode roundingMode)
Returns aBigDecimal
whose scale is the specified value, and whose unscaled value is determined by multiplying or dividing thisBigDecimal
's unscaled value by the appropriate power of ten to maintain its overall value.BigDecimal.sqrt(MathContext mc)
Returns an approximation to the square root ofthis
with rounding according to the context settings.BigDecimal.stripTrailingZeros()
Returns aBigDecimal
which is numerically equal to this one but with any trailing zeros removed from the representation.BigDecimal.subtract(BigDecimal subtrahend)
Returns aBigDecimal
whose value is(this - subtrahend)
, and whose scale ismax(this.scale(), subtrahend.scale())
.BigDecimal.subtract(BigDecimal subtrahend, MathContext mc)
Returns aBigDecimal
whose value is(this - subtrahend)
, with rounding according to the context settings.BigDecimal.ulp()
Returns the size of an ulp, a unit in the last place, of thisBigDecimal
.static BigDecimal
BigDecimal.valueOf(double val)
Translates adouble
into aBigDecimal
, using thedouble
's canonical string representation provided by theDouble.toString(double)
method.static BigDecimal
BigDecimal.valueOf(long val)
Translates along
value into aBigDecimal
with a scale of zero.static BigDecimal
BigDecimal.valueOf(long unscaledVal, int scale)
Translates along
unscaled value and anint
scale into aBigDecimal
.Modifier and TypeMethodDescriptionBigDecimal.add(BigDecimal augend)
Returns aBigDecimal
whose value is(this + augend)
, and whose scale ismax(this.scale(), augend.scale())
.BigDecimal.add(BigDecimal augend, MathContext mc)
Returns aBigDecimal
whose value is(this + augend)
, with rounding according to the context settings.int
BigDecimal.compareTo(BigDecimal val)
Compares thisBigDecimal
with the specifiedBigDecimal
.BigDecimal.divide(BigDecimal divisor)
Returns aBigDecimal
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) anArithmeticException
is thrown.BigDecimal.divide(BigDecimal divisor, int roundingMode)
Deprecated.The methoddivide(BigDecimal, RoundingMode)
should be used in preference to this legacy method.BigDecimal.divide(BigDecimal divisor, int scale, int roundingMode)
Deprecated.The methoddivide(BigDecimal, int, RoundingMode)
should be used in preference to this legacy method.BigDecimal.divide(BigDecimal divisor, int scale, RoundingMode roundingMode)
Returns aBigDecimal
whose value is(this / divisor)
, and whose scale is as specified.BigDecimal.divide(BigDecimal divisor, MathContext mc)
Returns aBigDecimal
whose value is(this / divisor)
, with rounding according to the context settings.BigDecimal.divide(BigDecimal divisor, RoundingMode roundingMode)
Returns aBigDecimal
whose value is(this / divisor)
, and whose scale isthis.scale()
.BigDecimal.divideAndRemainder(BigDecimal divisor)
Returns a two-elementBigDecimal
array containing the result ofdivideToIntegralValue
followed by the result ofremainder
on the two operands.BigDecimal.divideAndRemainder(BigDecimal divisor, MathContext mc)
Returns a two-elementBigDecimal
array containing the result ofdivideToIntegralValue
followed by the result ofremainder
on the two operands calculated with rounding according to the context settings.BigDecimal.divideToIntegralValue(BigDecimal divisor)
Returns aBigDecimal
whose value is the integer part of the quotient(this / divisor)
rounded down.BigDecimal.divideToIntegralValue(BigDecimal divisor, MathContext mc)
Returns aBigDecimal
whose value is the integer part of(this / divisor)
.BigDecimal.max(BigDecimal val)
Returns the maximum of thisBigDecimal
andval
.BigDecimal.min(BigDecimal val)
Returns the minimum of thisBigDecimal
andval
.BigDecimal.multiply(BigDecimal multiplicand)
Returns aBigDecimal
whose value is(this × multiplicand)
, and whose scale is(this.scale() + multiplicand.scale())
.BigDecimal.multiply(BigDecimal multiplicand, MathContext mc)
Returns aBigDecimal
whose value is(this × multiplicand)
, with rounding according to the context settings.BigDecimal.remainder(BigDecimal divisor)
Returns aBigDecimal
whose value is(this % divisor)
.BigDecimal.remainder(BigDecimal divisor, MathContext mc)
Returns aBigDecimal
whose value is(this % divisor)
, with rounding according to the context settings.BigDecimal.subtract(BigDecimal subtrahend)
Returns aBigDecimal
whose value is(this - subtrahend)
, and whose scale ismax(this.scale(), subtrahend.scale())
.BigDecimal.subtract(BigDecimal subtrahend, MathContext mc)
Returns aBigDecimal
whose value is(this - subtrahend)
, with rounding according to the context settings. -
Uses of BigDecimal in java.sql
Modifier and TypeMethodDescriptionCallableStatement.getBigDecimal(int parameterIndex)
Retrieves the value of the designated JDBCNUMERIC
parameter as ajava.math.BigDecimal
object with as many digits to the right of the decimal point as the value contains.CallableStatement.getBigDecimal(int parameterIndex, int scale)
Deprecated.usegetBigDecimal(int parameterIndex)
orgetBigDecimal(String parameterName)
CallableStatement.getBigDecimal(String parameterName)
Retrieves the value of a JDBCNUMERIC
parameter as ajava.math.BigDecimal
object with as many digits to the right of the decimal point as the value contains.ResultSet.getBigDecimal(int columnIndex)
Retrieves the value of the designated column in the current row of thisResultSet
object as ajava.math.BigDecimal
with full precision.ResultSet.getBigDecimal(int columnIndex, int scale)
Deprecated.UsegetBigDecimal(int columnIndex)
orgetBigDecimal(String columnLabel)
ResultSet.getBigDecimal(String columnLabel)
Retrieves the value of the designated column in the current row of thisResultSet
object as ajava.math.BigDecimal
with full precision.ResultSet.getBigDecimal(String columnLabel, int scale)
Deprecated.UsegetBigDecimal(int columnIndex)
orgetBigDecimal(String columnLabel)
SQLInput.readBigDecimal()
Reads the next attribute in the stream and returns it as ajava.math.BigDecimal
object in the Java programming language.Modifier and TypeMethodDescriptionvoid
CallableStatement.setBigDecimal(String parameterName, BigDecimal x)
Sets the designated parameter to the givenjava.math.BigDecimal
value.void
PreparedStatement.setBigDecimal(int parameterIndex, BigDecimal x)
Sets the designated parameter to the givenjava.math.BigDecimal
value.void
ResultSet.updateBigDecimal(int columnIndex, BigDecimal x)
Updates the designated column with ajava.math.BigDecimal
value.void
ResultSet.updateBigDecimal(String columnLabel, BigDecimal x)
Updates the designated column with ajava.sql.BigDecimal
value.void
SQLOutput.writeBigDecimal(BigDecimal x)
Writes the next attribute to the stream as a java.math.BigDecimal object. -
Uses of BigDecimal in java.util
Modifier and TypeMethodDescriptionScanner.nextBigDecimal()
Scans the next token of the input as aBigDecimal
. -
Uses of BigDecimal in javax.management.openmbean
Modifier and TypeFieldDescriptionstatic SimpleType<BigDecimal>
SimpleType.BIGDECIMAL
TheSimpleType
instance describing values whose Java class name isjava.math.BigDecimal
. -
Uses of BigDecimal in javax.sql
Modifier and TypeMethodDescriptionvoid
RowSet.setBigDecimal(int parameterIndex, BigDecimal x)
Sets the designated parameter in thisRowSet
object's command to the givenjava.math.BigDecimal
value.void
RowSet.setBigDecimal(String parameterName, BigDecimal x)
Sets the designated parameter to the givenjava.math.BigDecimal
value. -
Uses of BigDecimal in javax.sql.rowset
Modifier and TypeMethodDescriptionvoid
BaseRowSet.setBigDecimal(int parameterIndex, BigDecimal x)
Sets the designated parameter to the givenjava.lang.BigDecimal
value.void
BaseRowSet.setBigDecimal(String parameterName, BigDecimal x)
Sets the designated parameter to the givenjava.math.BigDecimal
value. -
Uses of BigDecimal in javax.sql.rowset.serial
Modifier and TypeMethodDescriptionSQLInputImpl.readBigDecimal()
Retrieves the next attribute in thisSQLInputImpl
object as ajava.math.BigDecimal
.Modifier and TypeMethodDescriptionvoid
SQLOutputImpl.writeBigDecimal(BigDecimal x)
Writes ajava.math.BigDecimal
object in the Java programming language to thisSQLOutputImpl
object. -
Uses of BigDecimal in javax.xml.datatype
Modifier and TypeMethodDescriptionabstract BigDecimal
XMLGregorianCalendar.getFractionalSecond()
Returns fractional seconds.Modifier and TypeMethodDescriptionabstract Duration
Duration.multiply(BigDecimal factor)
Computes a new duration whose value isfactor
times longer than the value of this duration.abstract Duration
DatatypeFactory.newDuration(boolean isPositive, BigInteger years, BigInteger months, BigInteger days, BigInteger hours, BigInteger minutes, BigDecimal seconds)
Obtain a new instance of aDuration
specifying theDuration
as isPositive, years, months, days, hours, minutes, seconds.abstract XMLGregorianCalendar
DatatypeFactory.newXMLGregorianCalendar(BigInteger year, int month, int day, int hour, int minute, int second, BigDecimal fractionalSecond, int timezone)
Constructor allowing for complete value spaces allowed by W3C XML Schema 1.0 recommendation for xsd:dateTime and related builtin datatypes.DatatypeFactory.newXMLGregorianCalendarTime(int hours, int minutes, int seconds, BigDecimal fractionalSecond, int timezone)
Create a Java instance of XML Schema builtin datatype time.abstract void
XMLGregorianCalendar.setFractionalSecond(BigDecimal fractional)
Set fractional seconds.void
XMLGregorianCalendar.setTime(int hour, int minute, int second, BigDecimal fractional)
Set time as one unit, including the optional infinite precision fractional seconds.
divide(BigDecimal, RoundingMode)
should be used in preference to this legacy method.