java.math

Class BigDecimal

Implemented Interfaces:
Comparable<T>, Serializable

public class BigDecimal
extends Number
implements Comparable<T>

Immutable, arbitrary-precision signed decimal numbers. A BigDecimal consists of an arbitrary precision integer unscaled value and a 32-bit integer scale. If zero or positive, the scale is the number of digits to the right of the decimal point. If negative, the unscaled value of the number is multiplied by ten to the power of the negation of the scale. The value of the number represented by the BigDecimal is therefore (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.

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) should be used instead.

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.

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.

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.

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.

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.

Preferred Scales for Results of Arithmetic Operations

OperationPreferred Scale of Result
Addmax(addend.scale(), augend.scale())
Subtractmax(minuend.scale(), subtrahend.scale())
Multiplymultiplier.scale() + multiplicand.scale()
Dividedividend.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.

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
but
21/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.

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.

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.

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.

All methods and constructors for this class throw NullPointerException when passed a null object reference for any input parameter.

See Also:
BigInteger, MathContext, RoundingMode, SortedMap, SortedSet, Serialized Form

Field Summary

static BigDecimal
ONE
The value 1, with a scale of 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.
static int
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.
static BigDecimal
TEN
The value 10, with a scale of 0.
static BigDecimal
ZERO
The value 0, with a scale of 0.

Constructor Summary

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(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(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(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(double val)
Translates a double into a BigDecimal which is the exact decimal representation of the double's binary floating-point value.
BigDecimal(double val, MathContext mc)
Translates a double into a BigDecimal, with rounding according to the context settings.
BigDecimal(int val)
Translates an int into a BigDecimal.
BigDecimal(int val, MathContext mc)
Translates an int into a BigDecimal, with rounding according to the context settings.
BigDecimal(String val)
Translates the string representation of a BigDecimal into a 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(BigInteger val)
Translates a BigInteger into a BigDecimal.
BigDecimal(BigInteger unscaledVal, int scale)
Translates a BigInteger unscaled value and an int scale into a 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.
BigDecimal(BigInteger val, MathContext mc)
Translates a BigInteger into a BigDecimal rounding according to the context settings.
BigDecimal(long val)
Translates a long into a BigDecimal.
BigDecimal(long val, MathContext mc)
Translates a long into a BigDecimal, with rounding according to the context settings.

Method Summary

BigDecimal
abs()
Returns a BigDecimal whose value is the absolute value of this BigDecimal, and whose scale is 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
add(BigDecimal augend)
Returns a BigDecimal whose value is (this + augend), and whose scale is max(this.scale(), augend.scale()).
BigDecimal
add(BigDecimal augend, MathContext mc)
Returns a BigDecimal whose value is (this + augend), with rounding according to the context settings.
byte
byteValueExact()
Converts this BigDecimal to a byte, checking for lost information.
int
compareTo(BigDecimal val)
Compares this BigDecimal with the specified 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
divide(BigDecimal divisor, int roundingMode)
Returns a BigDecimal whose value is (this / divisor), and whose scale is 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
divide(BigDecimal divisor, int scale, RoundingMode roundingMode)
Returns a BigDecimal whose value is (this / divisor), and whose scale is as specified.
BigDecimal
divide(BigDecimal divisor, MathContext mc)
Returns a BigDecimal whose value is (this / divisor), with rounding according to the context settings.
BigDecimal
divide(BigDecimal divisor, RoundingMode roundingMode)
Returns a BigDecimal whose value is (this / divisor), and whose scale is 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[]
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 divisor)
Returns a BigDecimal whose value is the integer part of the quotient (this / divisor) rounded down.
BigDecimal
divideToIntegralValue(BigDecimal divisor, MathContext mc)
Returns a BigDecimal whose value is the integer part of (this / divisor).
double
doubleValue()
Converts this BigDecimal to a double.
boolean
equals(Object x)
Compares this BigDecimal with the specified Object for equality.
float
floatValue()
Converts this BigDecimal to a float.
int
hashCode()
Returns the hash code for this BigDecimal.
int
intValue()
Converts this BigDecimal to an int.
int
intValueExact()
Converts this BigDecimal to an int, checking for lost information.
long
longValue()
Converts this BigDecimal to a long.
long
longValueExact()
Converts this BigDecimal to a long, checking for lost information.
BigDecimal
max(BigDecimal val)
Returns the maximum of this BigDecimal and val.
BigDecimal
min(BigDecimal val)
Returns the minimum of this BigDecimal and 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
movePointRight(int n)
Returns a BigDecimal which is equivalent to this one with the decimal point moved n places to the right.
BigDecimal
multiply(BigDecimal multiplicand)
Returns a BigDecimal whose value is (this × multiplicand), and whose scale is (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
negate()
Returns a BigDecimal whose value is (-this), and whose scale is this.scale().
BigDecimal
negate(MathContext mc)
Returns a BigDecimal whose value is (-this), with rounding according to the context settings.
BigDecimal
plus()
Returns a BigDecimal whose value is (+this), and whose scale is this.scale().
BigDecimal
plus(MathContext mc)
Returns a BigDecimal whose value is (+this), with rounding according to the context settings.
BigDecimal
pow(int n)
Returns a BigDecimal whose value is (thisn), The power is computed exactly, to unlimited precision.
BigDecimal
pow(int n, MathContext mc)
Returns a BigDecimal whose value is (thisn).
int
precision()
Returns the precision of this BigDecimal.
BigDecimal
remainder(BigDecimal divisor)
Returns a BigDecimal whose value is (this % divisor).
BigDecimal
remainder(BigDecimal divisor, MathContext mc)
Returns a BigDecimal whose value is (this % divisor), with rounding according to the context settings.
BigDecimal
round(MathContext mc)
Returns a BigDecimal rounded according to the MathContext settings.
int
scale()
Returns the scale of this BigDecimal.
BigDecimal
scaleByPowerOfTen(int n)
Returns a BigDecimal whose numerical value is equal to (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
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
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.
short
shortValueExact()
Converts this BigDecimal to a short, checking for lost information.
int
signum()
Returns the signum function of this BigDecimal.
BigDecimal
stripTrailingZeros()
Returns a BigDecimal which is numerically equal to this one but with any trailing zeros removed from the representation.
BigDecimal
subtract(BigDecimal subtrahend)
Returns a BigDecimal whose value is (this - subtrahend), and whose scale is max(this.scale(), subtrahend.scale()).
BigDecimal
subtract(BigDecimal subtrahend, MathContext mc)
Returns a BigDecimal whose value is (this - subtrahend), with rounding according to the context settings.
BigInteger
toBigInteger()
Converts this BigDecimal to a BigInteger.
BigInteger
toBigIntegerExact()
Converts this BigDecimal to a BigInteger, checking for lost information.
String
toEngineeringString()
Returns a string representation of this BigDecimal, using engineering notation if an exponent is needed.
String
toPlainString()
Returns a string representation of this BigDecimal without an exponent field.
String
toString()
Returns the string representation of this BigDecimal, using scientific notation if an exponent is needed.
BigDecimal
ulp()
Returns the size of an ulp, a unit in the last place, of this BigDecimal.
BigInteger
unscaledValue()
Returns a BigInteger whose value is the unscaled value of this 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.
static BigDecimal
valueOf(long val)
Translates a long value into a BigDecimal with a scale of zero.
static BigDecimal
valueOf(long unscaledVal, int scale)
Translates a long unscaled value and an int scale into a BigDecimal.

Methods inherited from class java.lang.Number

byteValue, doubleValue, floatValue, intValue, longValue, shortValue

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

ONE

public static final BigDecimal ONE
The value 1, with a scale of 0.
Since:
1.5
Usages and Demos :

View More Examples of ONE
   1: 
   2:     protected abstract void printf(FormatContext context, boolean negative, BigDecimal argument);
   3: 
   4:         ...
   5:             context.writeRestricted(String.valueOf(argument));
   6:         } else if (argument instanceof BigDecimal) {
   7:         ...
   8:             BigDecimal bigDecimal = (BigDecimal) argument;
   9:             printf(context, bigDecimal.signum() < 0, bigDecimal.abs());
  10:         ...
  11:             BigDecimal roundedArgument = argument.setScale(argument.scale() - shift, BigDecimal.ROUND_HALF_UP);
  12:             if (roundedArgument.compareTo(new BigDecimal(BigInteger.ONE, 4)) >= 0 &&

View Full Code Here
   1: import java.io.StringReader;
   2: import java.math.BigDecimal;
   3: import java.math.BigInteger;
   4:         ...
   5:   {
   6:     BigDecimal[] nums = new BigDecimal[512];
   7:     int i = 0;
   8:         ...
   9:     nums[i++] = BigDecimal.ZERO;
  10:     nums[i++] = BigDecimal.ONE;
  11:     nums[i++] = BigDecimal.valueOf(-1);
  12:         ...
  13:     nums[i++] = BigInteger.ZERO;
  14:     nums[i++] = BigInteger.ONE;

View Full Code Here

ROUND_CEILING

public static final int ROUND_CEILING
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.
Field Value:
2
Usages and Demos :

View More Examples of BigDecimal.ROUND_CEILING
   1:     protected Object performCalculation(BigDecimal value) {
   2:         return value.setScale(0, BigDecimal.ROUND_CEILING);
   3:     }
   4: 
   5:     protected String[] getSqlFunction(SqlGenerationContext context) {

View Full Code Here
   1:         if (ROUND_CEILING.equals(mode)) {
   2:             return BigDecimal.ROUND_CEILING;
   3:         }
   4:         else if (ROUND_DOWN.equals(mode)) {
   5:             return BigDecimal.ROUND_DOWN;

View Full Code Here
   1:             {
   2:                 BigDecimal.ROUND_CEILING,
   3:                 BigDecimal.ROUND_DOWN ,
   4:                 BigDecimal.ROUND_FLOOR ,
   5:                 BigDecimal.ROUND_HALF_DOWN ,

View Full Code Here
   1:         switch (roundingMethod) {
   2:         case BigDecimal.ROUND_CEILING :
   3:             if (sign == -1) {
   4:                 unscaled = Math.floor(nextAfter(unscaled, Double.NEGATIVE_INFINITY));
   5:             } else {

View Full Code Here
   1:       if (n instanceof BigDecimal) {
   2:         return ((BigDecimal)n).setScale(0, BigDecimal.ROUND_CEILING);
   3:       } else {
   4:         ...
   5:         if (d.compareTo(DECIMAL_ZERO) < 0) {
   6:           return d.setScale(0, BigDecimal.ROUND_CEILING);
   7:         } else {
   8:           return d.setScale(0, BigDecimal.ROUND_FLOOR);
   9:         }

View Full Code Here

ROUND_DOWN

public static final int ROUND_DOWN
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.
Field Value:
1
Usages and Demos :

View More Examples of BigDecimal.ROUND_DOWN
   1:         else if (ROUND_DOWN.equals(mode)) {
   2:             return BigDecimal.ROUND_DOWN;
   3:         }
   4:         else if (ROUND_FLOOR.equals(mode)) {
   5:             return BigDecimal.ROUND_FLOOR;

View Full Code Here
   1:         BigDecimal secondsValue = secondsValue();        
   2:         BigDecimal m = secondsValue.divide(SIXTY_DECIMAL, 0, BigDecimal.ROUND_DOWN);
   3:         seconds = nullIfZero(secondsValue.subtract(SIXTY_DECIMAL.multiply(m)));    
   4:         r = m.toBigInteger().divideAndRemainder(SIXTY);        
   5:         

View Full Code Here
   1:     public int hashCode() {
   2:         BigDecimal round = value.setScale(0, BigDecimal.ROUND_DOWN);
   3:         long value = round.longValue();
   4:         ...
   5:         return value.scale()==0 ||
   6:                value.equals(value.setScale(0, BigDecimal.ROUND_DOWN));
   7:     }
   8:         ...
   9:                     case Token.IDIV:
  10:                         BigInteger quot = value.divide(((DecimalValue)other).value, 0, BigDecimal.ROUND_DOWN).toBigInteger();
  11:                         return BigIntegerValue.makeValue(quot);

View Full Code Here
   1:             throw new XPathException("FOAR0001: division by zero");
   2:         BigInteger quot = value.divide(dv.value, 0, BigDecimal.ROUND_DOWN).toBigInteger();
   3:         return new IntegerValue(quot);
   4:         ...
   5:             BigDecimal quotient =
   6:                 value.divide(((DecimalValue) other).value, BigDecimal.ROUND_DOWN);
   7:             BigDecimal remainder =
   8:         ...
   9:                 value.subtract(quotient.setScale(0, BigDecimal.ROUND_DOWN).multiply(((DecimalValue) other).value));
  10:             return new DecimalValue(remainder);

View Full Code Here
   1:                 BigDecimal.ROUND_CEILING,
   2:                 BigDecimal.ROUND_DOWN ,
   3:                 BigDecimal.ROUND_FLOOR ,
   4:                 BigDecimal.ROUND_HALF_DOWN ,
   5:                 BigDecimal.ROUND_HALF_EVEN ,

View Full Code Here

ROUND_FLOOR

public static final int ROUND_FLOOR
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.
Field Value:
3
Usages and Demos :

View More Examples of BigDecimal.ROUND_FLOOR
   1:     protected Object performCalculation(BigDecimal value) {
   2:         return value.setScale(0, BigDecimal.ROUND_FLOOR);
   3:     }
   4: 
   5:     protected String[] getSqlFunction(SqlGenerationContext context) {

View Full Code Here
   1:         else if (ROUND_FLOOR.equals(mode)) {
   2:             return BigDecimal.ROUND_FLOOR;
   3:         }
   4:         else if (ROUND_HALF_DOWN.equals(mode)) {
   5:             return BigDecimal.ROUND_HALF_DOWN;

View Full Code Here
   1:                 BigDecimal.ROUND_DOWN ,
   2:                 BigDecimal.ROUND_FLOOR ,
   3:                 BigDecimal.ROUND_HALF_DOWN ,
   4:                 BigDecimal.ROUND_HALF_EVEN ,
   5:                 BigDecimal.ROUND_HALF_UP ,

View Full Code Here
   1:         try {
   2:             return d1.divide(d2, DIVIDE_PRECISION, BigDecimal.ROUND_FLOOR) ;
   3:         } catch (ArithmeticException ex)
   4:         ...
   5:             case OP_DECIMAL:
   6:                 BigDecimal dec = v.getDecimal().setScale(0, BigDecimal.ROUND_FLOOR) ;
   7:                 return NodeValue.makeDecimal(dec) ;
   8:             case OP_FLOAT:
   9:                 return NodeValue.makeDouble( Math.floor(v.getFloat()) ) ;

View Full Code Here
   1:             break;
   2:         case BigDecimal.ROUND_FLOOR :
   3:             if (sign == -1) {
   4:                 unscaled = Math.ceil(nextAfter(unscaled, Double.POSITIVE_INFINITY));
   5:             } else {

View Full Code Here

ROUND_HALF_DOWN

public static final int ROUND_HALF_DOWN
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 > 0.5; otherwise, behaves as for ROUND_DOWN.
Field Value:
5
Usages and Demos :

View More Examples of BigDecimal.ROUND_HALF_DOWN
   1:     protected Object performCalculation(BigDecimal value1, BigDecimal value2) {
   2:         return value1.divide(value2, 8, BigDecimal.ROUND_HALF_DOWN);
   3:     }
   4: 
   5:     protected String getMathSymbol() {

View Full Code Here
   1:         if (value1.scale() > scale)
   2:             return value1.setScale(scale, BigDecimal.ROUND_HALF_DOWN);
   3:         else
   4:             return value1;
   5:     }

View Full Code Here
   1:         value2 = value2.abs();
   2:         BigDecimal quotient = value1.divide(value2, BigDecimal.ROUND_HALF_DOWN);
   3:         quotient = quotient.setScale(0, BigDecimal.ROUND_DOWN);
   4:         return value1.subtract(quotient.multiply(value2));
   5:     }

View Full Code Here
   1:         else if (ROUND_HALF_DOWN.equals(mode)) {
   2:             return BigDecimal.ROUND_HALF_DOWN;
   3:         }
   4:         else if (ROUND_HALF_EVEN.equals(mode)) {
   5:             return BigDecimal.ROUND_HALF_EVEN;

View Full Code Here
   1:             case -1:
   2:                 return new DecimalValue(value.setScale(0, BigDecimal.ROUND_HALF_DOWN));
   3:             case 0:
   4:         ...
   5:                                              Math.max(value.scale(), ((DecimalValue)other).value.scale()));
   6:                         BigDecimal result = value.divide(((DecimalValue)other).value, scale, BigDecimal.ROUND_HALF_DOWN);
   7:                         return new DecimalValue(result);
   8:                     case Token.IDIV:
   9:                         BigInteger quot = value.divide(((DecimalValue)other).value, 0, BigDecimal.ROUND_DOWN).toBigInteger();

View Full Code Here

ROUND_HALF_EVEN

public static final 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. 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.
Field Value:
6
Usages and Demos :

View More Examples of BigDecimal.ROUND_HALF_EVEN
   1:     BigDecimal bd = new BigDecimal(aktuelleZeit);
   2:     bd = bd.setScale(4, BigDecimal.ROUND_HALF_EVEN);
   3:     aktuelleZeit = bd.floatValue();
   4:         ...
   5:     BigDecimal bd = new BigDecimal(time);
   6:     bd = bd.setScale(4, BigDecimal.ROUND_HALF_EVEN);
   7: 
   8:     aktuelleZeit += bd.floatValue();
   9:   }

View Full Code Here
   1:     private static final int roundingMode = 
   2:         BigDecimal.ROUND_HALF_EVEN;
   3: 
   4:     private int digits;
   5:     

View Full Code Here
   1:     private static final int roundingMode = 
   2:         BigDecimal.ROUND_HALF_EVEN;
   3: 
   4:     public Pi(int digits) {
   5:         this.digits = digits;

View Full Code Here
   1:                         _scale == AUTO ? bd.scale()+2: _scale,
   2:                         BigDecimal.ROUND_HALF_EVEN);
   3:                 else
   4:                     throw new WrongValueException(this, MZul.NUMBER_REQUIRED, value);
   5:             return bd;

View Full Code Here
   1:         else if (ROUND_HALF_EVEN.equals(mode)) {
   2:             return BigDecimal.ROUND_HALF_EVEN;
   3:         }
   4:         else if (ROUND_HALF_UP.equals(mode)) {
   5:             return BigDecimal.ROUND_HALF_UP;

View Full Code Here

ROUND_HALF_UP

public static final int ROUND_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 >= 0.5; otherwise, behaves as for ROUND_DOWN. Note that this is the rounding mode that most of us were taught in grade school.
Field Value:
4
Usages and Demos :

View More Examples of BigDecimal.ROUND_HALF_UP
   1:       }
   2:       return computedResult.divide(new BigDecimal(count), BigDecimal.ROUND_HALF_UP);
   3:     }
   4:         ...
   5:     }
   6:     return computedResult.divide(new BigDecimal(values.length), BigDecimal.ROUND_HALF_UP);
   7:   }
   8: }

View Full Code Here
   1:         setT_Amount(new BigDecimal(testNo));
   2:         setT_Number(Env.ONE.divide(new BigDecimal(testNo), BigDecimal.ROUND_HALF_UP));
   3: 
   4:     
   5:     protected boolean beforeDelete ()

View Full Code Here
   1:     {
   2:       return total.divide(new BigDecimal(count), BigDecimal.ROUND_HALF_UP);
   3:     }
   4:     return new BigDecimal(0.0);
   5:   }

View Full Code Here
   1:         if (count != 0)
   2:             retValue = total.divide(new BigDecimal(count), 2, BigDecimal.ROUND_HALF_UP);
   3:         return retValue;

View Full Code Here
   1:                 PriceItemBean pib = (PriceItemBean)it.next();
   2:                 BigDecimal price = pib.getPricePerPound().multiply(new BigDecimal("1.35")).setScale(2, BigDecimal.ROUND_HALF_UP);
   3:                 RetailPriceItem rpi = new RetailPriceItem(pib.getCoffeeName(), pib.getPricePerPound(), price, distributor);
   4:         ...
   5:         PriceItemBean pib = (PriceItemBean)it.next();
   6:         BigDecimal price = pib.getPricePerPound().multiply(new BigDecimal("1.35")).setScale(2, BigDecimal.ROUND_HALF_UP);
   7:         RetailPriceItem rpi = new RetailPriceItem(pib.getCoffeeName(), pib.getPricePerPound(), price, SAAJOrderURL);
   8:         retailPriceItems.add(rpi);
   9:       }

View Full Code Here

ROUND_UNNECESSARY

public static final int ROUND_UNNECESSARY
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.
Field Value:
7
Usages and Demos :

View More Examples of BigDecimal.ROUND_UNNECESSARY
   1:         return bigDecimal==null ? null : 
   2:             bigDecimal.setScale(0, BigDecimal.ROUND_UNNECESSARY).unscaledValue();
   3:     }
   4: 
   5:     public void set(PreparedStatement st, Object value, int index)

View Full Code Here
   1:         }
   2:         case BigDecimal.ROUND_UNNECESSARY :
   3:             if (unscaled != Math.floor(unscaled)) {
   4:                 throw new ArithmeticException("Inexact result from rounding");
   5:             }

View Full Code Here

ROUND_UP

public static final int ROUND_UP
Rounding mode to round away from zero. Always increments the digit prior to a nonzero discarded fraction. Note that this rounding mode never decreases the magnitude of the calculated value.
Field Value:
0
Usages and Demos :

View More Examples of BigDecimal.ROUND_UP
   1:                     s.push(((BigDecimal)s.pop()).divide((BigDecimal)s.pop(),
   2:                         BigDecimal.ROUND_UP));
   3:                     break;
   4:                 case '=':
   5:                     System.out.println(s.pop());

View Full Code Here
   1:         BigDecimal result = dollars.multiply(yenRate);
   2:         return result.setScale(2, BigDecimal.ROUND_UP);
   3:     }
   4:         ...
   5:         BigDecimal result = yen.multiply(euroRate);
   6:         return result.setScale(2, BigDecimal.ROUND_UP);
   7:     }
   8:         ...
   9:         BigDecimal result = dollars.multiply(realRate);
  10:         return result.setScale(2, BigDecimal.ROUND_UP);
  11:     }

View Full Code Here
   1:         Money five = new Money("5");
   2:         assertEquals(new Money("25"), five.multiply(new BigDecimal("5"), BigDecimal.ROUND_UP));
   3:     }
   4: 
   5:     public void testLessThanZeror() {

View Full Code Here
   1:         else if (ROUND_UP.equals(mode)) {
   2:             return BigDecimal.ROUND_UP;
   3:         }
   4:         else {
   5:             throw new IllegalArgumentException("'" + mode + "' is not a valid rounding mode.  Please specify one of the constants defined in " + NumberRounder.class.getName());

View Full Code Here
   1:                 BigDecimal round = new BigDecimal(max / 1000d);
   2:                 round = round.setScale(0, BigDecimal.ROUND_UP);
   3:                 double topValue = round.doubleValue() * 1000;
   4:                 yaxis.setUserDefinedScale(0, 500);
   5:                 yaxis.setNumItems((int) (topValue / 500)+1);

View Full Code Here

TEN

public static final BigDecimal TEN
The value 10, with a scale of 0.
Since:
1.5

ZERO

public static final BigDecimal ZERO
The value 0, with a scale of 0.
Since:
1.5
Usages and Demos :

View More Examples of ZERO
   1: import java.io.Serializable;
   2: import java.math.BigDecimal;
   3: import java.math.BigInteger;
   4:         ...
   5:   @Override
   6:   public BigDecimal toBigDecimal()
   7:   {
   8:         ...
   9:     return BigDecimal.ZERO;
  10:   }
  11:         ...
  12:   {
  13:     return BigInteger.ZERO;

View Full Code Here
   1: import java.io.StringReader;
   2: import java.math.BigDecimal;
   3: import java.math.BigInteger;
   4:         ...
   5:   {
   6:     BigDecimal[] nums = new BigDecimal[512];
   7:     int i = 0;
   8:         ...
   9:     nums[i++] = BigDecimal.ZERO;
  10:     nums[i++] = BigDecimal.ONE;
  11:         ...
  12:     int i = 0;
  13:     nums[i++] = BigInteger.ZERO;

View Full Code Here
   1: 
   2: import java.math.BigDecimal;
   3: import java.math.BigInteger;
   4:         ...
   5: 
   6:   private static final BigDecimal ZERO = BigDecimal.ZERO;
   7:         ...
   8:   private static final BigDecimal ONE = BigDecimal.ONE;
   9:   private static final BigDecimal TWO = new BigDecimal(2);
  10:         ...
  11: 
  12:     if (bd.compareTo(BigDecimal.ZERO) == 0)

View Full Code Here
   1: import java.lang.reflect.Method;
   2: import java.math.BigDecimal;
   3: import java.math.BigInteger;
   4:         ...
   5:     else if (BigInteger.class.isAssignableFrom(type)) {
   6:       return "java.math.BigInteger.ZERO";
   7:     }
   8:         ...
   9:     else if (BigDecimal.class.isAssignableFrom(type)) {
  10:         ...
  11:       return "java.math.BigDecimal.ZERO";

View Full Code Here

Constructor Details

BigDecimal

public 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.

Note that if the sequence of characters is already available as a character array, using this constructor is faster than converting the char array to string and using the BigDecimal(String) constructor .

Parameters:
in - char array that is the source of characters.
Throws:
NumberFormatException - if in is not a valid representation of a BigDecimal.
Since:
1.5
Usages and Demos :

View More Examples of BigDecimal(char[] in)
   1:         }
   2:         return (new BigDecimal(Double.toString(value.doubleValue()))).toString();
   3:     }
   4:         ...
   5:     public static final String toString(final double value) {
   6:         return (new BigDecimal("" + value)).toString();
   7:     }
   8: 

View Full Code Here
   1:     
   2:     public static final BigDecimal MAX_LONG = new BigDecimal("" + Long.MAX_VALUE);
   3:         ...
   4:     public static final BigDecimal MAX_INTEGER = new BigDecimal("" + Integer.MAX_VALUE);
   5:         ...
   6:     public static final BigDecimal MAX_SHORT = new BigDecimal("" + Short.MAX_VALUE);
   7:     public static final BigDecimal MAX_BYTE = new BigDecimal("" + Byte.MAX_VALUE);

View Full Code Here
   1:         }
   2:         return new BigDecimal(""+i);
   3:     }
   4:         ...
   5:         }
   6:         return new BigDecimal(""+i);
   7:     }
   8:     
   9:     

View Full Code Here

BigDecimal

public 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.

Note that if the sequence of characters is already available within a character array, using this constructor is faster than converting the char array to string and using the BigDecimal(String) constructor .

Parameters:
in - char array that is the source of characters.
offset - first character in the array to inspect.
len - number of characters to consider.
Throws:
NumberFormatException - if in is not a valid representation of a BigDecimal or the defined subarray is not wholly within in.
Since:
1.5
Usages and Demos :

View More Examples of BigDecimal(char[] in,int offset,int len)
   1:         try {
   2:             BigDecimal decimalNumber = new BigDecimal(number.replaceAll(",", ""));
   3:             if (decimalNumber.scale() == 0) {
   4:                 return formatNumber(decimalNumber.longValue());
   5:             } else {

View Full Code Here
   1:         }
   2:         return new java.math.BigDecimal(DateTimeUtil.diff(s,d1,d2));
   3:     }
   4:     
   5:     public static java.math.BigDecimal round(java.math.BigDecimal val,java.math.BigDecimal num){

View Full Code Here

BigDecimal

public 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.

Note that if the sequence of characters is already available within a character array, using this constructor is faster than converting the char array to string and using the BigDecimal(String) constructor .

Parameters:
in - char array that is the source of characters.
offset - first character in the array to inspect.
len - number of characters to consider..
mc - the context to use.
Throws:
ArithmeticException - if the result is inexact but the rounding mode is UNNECESSARY.
NumberFormatException - if in is not a valid representation of a BigDecimal or the defined subarray is not wholly within in.
Since:
1.5

BigDecimal

public 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.

Note that if the sequence of characters is already available as a character array, using this constructor is faster than converting the char array to string and using the BigDecimal(String) constructor .

Parameters:
in - char array that is the source of characters.
mc - the context to use.
Throws:
ArithmeticException - if the result is inexact but the rounding mode is UNNECESSARY.
NumberFormatException - if in is not a valid representation of a BigDecimal.
Since:
1.5
Usages and Demos :

View More Examples of BigDecimal(char[] in,MathContext mc)
   1:         BigInteger bi = parseBigInteger(1,Integer.MAX_VALUE);
   2:         BigDecimal d = new BigDecimal(bi,vidx-s);
   3:         if( second==null)   second = d;
   4:         else                second = second.add(d);
   5:     }

View Full Code Here
   1:             BigDecimal bd = j == 0 ? BigDecimals.ZERO:
   2:                 new BigDecimal(j < 0 ? val: val.substring(0, j));
   3:             if (_scale != AUTO) bd = bd.setScale(_scale);
   4:             if (j <= 0) return bd;

View Full Code Here
   1:     List<BigDecimal> lbd = Arrays.asList(
   2:       new BigDecimal(1.1, mc), new BigDecimal(2.2, mc),
   3:         ...
   4:       new BigDecimal(3.3, mc), new BigDecimal(4.4, mc));
   5:     BigDecimal rbd = reduce(lbd, new BigDecimalAdder());
   6:     print(rbd);

View Full Code Here
   1:     BigInteger b = new BigInteger(s.toString());
   2:     BigDecimal dec = new BigDecimal(b, scale);
   3: 
   4:     return dec;
   5:   }

View Full Code Here
   1:             int scale = in.readInt();
   2:             return new BigDecimal(value,scale);
   3:         }
   4:     }

View Full Code Here

BigDecimal

public BigDecimal(double val)
Translates a double into a BigDecimal which is the exact decimal representation of the double's binary floating-point value. The scale of the returned BigDecimal is the smallest value such that (10scale × val) is an integer.

Notes:

  1. The results of this constructor can be somewhat unpredictable. One might assume that writing new BigDecimal(0.1) in Java creates a BigDecimal which is exactly equal to 0.1 (an unscaled value of 1, with a scale of 1), but it is actually equal to 0.1000000000000000055511151231257827021181583404541015625. This is because 0.1 cannot be represented exactly as a double (or, for that matter, as a binary fraction of any finite length). Thus, the value that is being passed in to the constructor is not exactly equal to 0.1, appearances notwithstanding.
  2. The String constructor, on the other hand, is perfectly predictable: writing new BigDecimal("0.1") creates a BigDecimal which is exactly equal to 0.1, as one would expect. Therefore, it is generally recommended that the String constructor be used in preference to this one.
  3. When a double must be used as a source for a BigDecimal, note that this constructor provides an exact conversion; it does not give the same result as converting the double to a String using the Double.toString(double) method and then using the BigDecimal(String) constructor. To get that result, use the static valueOf(double) method.
Parameters:
val - double value to be converted to BigDecimal.
Throws:
NumberFormatException - if val is infinite or NaN.
Usages and Demos :

View More Examples of BigDecimal(double val)
   1:         }
   2:         return (new BigDecimal(Double.toString(value.doubleValue()))).toString();
   3:     }
   4:         ...
   5:     public static final String toString(final double value) {
   6:         return (new BigDecimal("" + value)).toString();
   7:     }
   8: 

View Full Code Here
   1:     
   2:     public static final BigDecimal MAX_LONG = new BigDecimal("" + Long.MAX_VALUE);
   3:         ...
   4:     public static final BigDecimal MAX_INTEGER = new BigDecimal("" + Integer.MAX_VALUE);
   5:         ...
   6:     public static final BigDecimal MAX_SHORT = new BigDecimal("" + Short.MAX_VALUE);
   7:     public static final BigDecimal MAX_BYTE = new BigDecimal("" + Byte.MAX_VALUE);

View Full Code Here
   1:         }
   2:         return new BigDecimal(""+i);
   3:     }
   4:         ...
   5:         }
   6:         return new BigDecimal(""+i);
   7:     }
   8:     
   9:     

View Full Code Here

BigDecimal

public BigDecimal(double val,
                  MathContext mc)
Translates a double into a BigDecimal, with rounding according to the context settings. The scale of the BigDecimal is the smallest value such that (10scale × val) is an integer.

The results of this constructor can be somewhat unpredictable and its use is generally not recommended; see the notes under the BigDecimal(double) constructor.

Parameters:
val - double value to be converted to BigDecimal.
mc - the context to use.
Throws:
ArithmeticException - if the result is inexact but the RoundingMode is UNNECESSARY.
NumberFormatException - if val is infinite or NaN.
Since:
1.5
Usages and Demos :

View More Examples of BigDecimal(double val,MathContext mc)
   1:         BigInteger bi = parseBigInteger(1,Integer.MAX_VALUE);
   2:         BigDecimal d = new BigDecimal(bi,vidx-s);
   3:         if( second==null)   second = d;
   4:         else                second = second.add(d);
   5:     }

View Full Code Here
   1:             BigDecimal bd = j == 0 ? BigDecimals.ZERO:
   2:                 new BigDecimal(j < 0 ? val: val.substring(0, j));
   3:             if (_scale != AUTO) bd = bd.setScale(_scale);
   4:             if (j <= 0) return bd;

View Full Code Here
   1:     List<BigDecimal> lbd = Arrays.asList(
   2:       new BigDecimal(1.1, mc), new BigDecimal(2.2, mc),
   3:         ...
   4:       new BigDecimal(3.3, mc), new BigDecimal(4.4, mc));
   5:     BigDecimal rbd = reduce(lbd, new BigDecimalAdder());
   6:     print(rbd);

View Full Code Here
   1:     BigInteger b = new BigInteger(s.toString());
   2:     BigDecimal dec = new BigDecimal(b, scale);
   3: 
   4:     return dec;
   5:   }

View Full Code Here
   1:             int scale = in.readInt();
   2:             return new BigDecimal(value,scale);
   3:         }
   4:     }

View Full Code Here

BigDecimal

public BigDecimal(int val)
Translates an int into a BigDecimal. The scale of the BigDecimal is zero.
Parameters:
val - int value to be converted to BigDecimal.
Since:
1.5
Usages and Demos :

View More Examples of BigDecimal(int val)
   1:         }
   2:         return (new BigDecimal(Double.toString(value.doubleValue()))).toString();
   3:     }
   4:         ...
   5:     public static final String toString(final double value) {
   6:         return (new BigDecimal("" + value)).toString();
   7:     }
   8: 

View Full Code Here
   1:     
   2:     public static final BigDecimal MAX_LONG = new BigDecimal("" + Long.MAX_VALUE);
   3:         ...
   4:     public static final BigDecimal MAX_INTEGER = new BigDecimal("" + Integer.MAX_VALUE);
   5:         ...
   6:     public static final BigDecimal MAX_SHORT = new BigDecimal("" + Short.MAX_VALUE);
   7:     public static final BigDecimal MAX_BYTE = new BigDecimal("" + Byte.MAX_VALUE);

View Full Code Here
   1:         }
   2:         return new BigDecimal(""+i);
   3:     }
   4:         ...
   5:         }
   6:         return new BigDecimal(""+i);
   7:     }
   8:     
   9:     

View Full Code Here

BigDecimal

public BigDecimal(int val,
                  MathContext mc)
Translates an int into a BigDecimal, with rounding according to the context settings. The scale of the BigDecimal, before any rounding, is zero.
Parameters:
val - int value to be converted to BigDecimal.
mc - the context to use.
Throws:
ArithmeticException - if the result is inexact but the rounding mode is UNNECESSARY.
Since:
1.5
Usages and Demos :

View More Examples of BigDecimal(int val,MathContext mc)
   1:         BigInteger bi = parseBigInteger(1,Integer.MAX_VALUE);
   2:         BigDecimal d = new BigDecimal(bi,vidx-s);
   3:         if( second==null)   second = d;
   4:         else                second = second.add(d);
   5:     }

View Full Code Here
   1:             BigDecimal bd = j == 0 ? BigDecimals.ZERO:
   2:                 new BigDecimal(j < 0 ? val: val.substring(0, j));
   3:             if (_scale != AUTO) bd = bd.setScale(_scale);
   4:             if (j <= 0) return bd;

View Full Code Here
   1:     List<BigDecimal> lbd = Arrays.asList(
   2:       new BigDecimal(1.1, mc), new BigDecimal(2.2, mc),
   3:         ...
   4:       new BigDecimal(3.3, mc), new BigDecimal(4.4, mc));
   5:     BigDecimal rbd = reduce(lbd, new BigDecimalAdder());
   6:     print(rbd);

View Full Code Here
   1:     BigInteger b = new BigInteger(s.toString());
   2:     BigDecimal dec = new BigDecimal(b, scale);
   3: 
   4:     return dec;
   5:   }

View Full Code Here
   1:             int scale = in.readInt();
   2:             return new BigDecimal(value,scale);
   3:         }
   4:     }

View Full Code Here

BigDecimal

public BigDecimal(String val)
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 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:

FractionPart:

Exponent:

ExponentIndicator:
e
E

SignedInteger:
opt

Digits:

Digit:
Character.isDigittrue

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. The value of the resulting scale must lie between Integer.MIN_VALUE and Integer.MAX_VALUE, inclusive.

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).

Examples:
The value of the returned BigDecimal is equal to significand × 10 exponent. For each string on the left, the resulting representation [BigInteger, scale] is shown on the right.

 "0"            [0,0]
 "0.00"         [0,2]
 "123"          [123,0]
 "-123"         [-123,0]
 "1.23E3"       [123,-1]
 "1.23E+3"      [123,-1]
 "12.3E+7"      [123,-6]
 "12.0"         [120,1]
 "12.3"         [123,1]
 "0.00123"      [123,5]
 "-1.23E-12"    [-123,14]
 "1234.5E-4"    [12345,5]
 "0E+7"         [0,-7]
 "-0"           [0,0]
 

Note: For values other than 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(double) constructor.

Parameters:
val - String representation of BigDecimal.
Throws:
NumberFormatException - if val is not a valid representation of a BigDecimal.
Usages and Demos :

View More Examples of BigDecimal(String val)
   1:         }
   2:         return (new BigDecimal(Double.toString(value.doubleValue()))).toString();
   3:     }
   4:         ...
   5:     public static final String toString(final double value) {
   6:         return (new BigDecimal("" + value)).toString();
   7:     }
   8: 

View Full Code Here
   1:     
   2:     public static final BigDecimal MAX_LONG = new BigDecimal("" + Long.MAX_VALUE);
   3:         ...
   4:     public static final BigDecimal MAX_INTEGER = new BigDecimal("" + Integer.MAX_VALUE);
   5:         ...
   6:     public static final BigDecimal MAX_SHORT = new BigDecimal("" + Short.MAX_VALUE);
   7:     public static final BigDecimal MAX_BYTE = new BigDecimal("" + Byte.MAX_VALUE);

View Full Code Here
   1:         }
   2:         return new BigDecimal(""+i);
   3:     }
   4:         ...
   5:         }
   6:         return new BigDecimal(""+i);
   7:     }
   8:     
   9:     

View Full Code Here

BigDecimal

public 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.
Parameters:
val - string representation of a BigDecimal.
mc - the context to use.
Throws:
ArithmeticException - if the result is inexact but the rounding mode is UNNECESSARY.
NumberFormatException - if val is not a valid representation of a BigDecimal.
Since:
1.5
Usages and Demos :

View More Examples of BigDecimal(String val,MathContext mc)
   1:         BigInteger bi = parseBigInteger(1,Integer.MAX_VALUE);
   2:         BigDecimal d = new BigDecimal(bi,vidx-s);
   3:         if( second==null)   second = d;
   4:         else                second = second.add(d);
   5:     }

View Full Code Here
   1:             BigDecimal bd = j == 0 ? BigDecimals.ZERO:
   2:                 new BigDecimal(j < 0 ? val: val.substring(0, j));
   3:             if (_scale != AUTO) bd = bd.setScale(_scale);
   4:             if (j <= 0) return bd;

View Full Code Here
   1:     List<BigDecimal> lbd = Arrays.asList(
   2:       new BigDecimal(1.1, mc), new BigDecimal(2.2, mc),
   3:         ...
   4:       new BigDecimal(3.3, mc), new BigDecimal(4.4, mc));
   5:     BigDecimal rbd = reduce(lbd, new BigDecimalAdder());
   6:     print(rbd);

View Full Code Here
   1:     BigInteger b = new BigInteger(s.toString());
   2:     BigDecimal dec = new BigDecimal(b, scale);
   3: 
   4:     return dec;
   5:   }

View Full Code Here
   1:             int scale = in.readInt();
   2:             return new BigDecimal(value,scale);
   3:         }
   4:     }

View Full Code Here

BigDecimal

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

View More Examples of BigDecimal(BigInteger val)
   1:         }
   2:         return (new BigDecimal(Double.toString(value.doubleValue()))).toString();
   3:     }
   4:         ...
   5:     public static final String toString(final double value) {
   6:         return (new BigDecimal("" + value)).toString();
   7:     }
   8: 

View Full Code Here
   1:     
   2:     public static final BigDecimal MAX_LONG = new BigDecimal("" + Long.MAX_VALUE);
   3:         ...
   4:     public static final BigDecimal MAX_INTEGER = new BigDecimal("" + Integer.MAX_VALUE);
   5:         ...
   6:     public static final BigDecimal MAX_SHORT = new BigDecimal("" + Short.MAX_VALUE);
   7:     public static final BigDecimal MAX_BYTE = new BigDecimal("" + Byte.MAX_VALUE);

View Full Code Here
   1:         }
   2:         return new BigDecimal(""+i);
   3:     }
   4:         ...
   5:         }
   6:         return new BigDecimal(""+i);
   7:     }
   8:     
   9:     

View Full Code Here

BigDecimal

public BigDecimal(BigInteger unscaledVal,
                  int scale)
Translates a BigInteger unscaled value and an int scale into a BigDecimal. The value of the BigDecimal is (unscaledVal × 10-scale).
Parameters:
unscaledVal - unscaled value of the BigDecimal.
scale - scale of the BigDecimal.
Usages and Demos :

View More Examples of BigDecimal(BigInteger unscaledVal,int scale)
   1:         BigInteger bi = parseBigInteger(1,Integer.MAX_VALUE);
   2:         BigDecimal d = new BigDecimal(bi,vidx-s);
   3:         if( second==null)   second = d;
   4:         else                second = second.add(d);
   5:     }

View Full Code Here
   1:             BigDecimal bd = j == 0 ? BigDecimals.ZERO:
   2:                 new BigDecimal(j < 0 ? val: val.substring(0, j));
   3:             if (_scale != AUTO) bd = bd.setScale(_scale);
   4:             if (j <= 0) return bd;

View Full Code Here
   1:     List<BigDecimal> lbd = Arrays.asList(
   2:       new BigDecimal(1.1, mc), new BigDecimal(2.2, mc),
   3:         ...
   4:       new BigDecimal(3.3, mc), new BigDecimal(4.4, mc));
   5:     BigDecimal rbd = reduce(lbd, new BigDecimalAdder());
   6:     print(rbd);

View Full Code Here
   1:     BigInteger b = new BigInteger(s.toString());
   2:     BigDecimal dec = new BigDecimal(b, scale);
   3: 
   4:     return dec;
   5:   }

View Full Code Here
   1:             int scale = in.readInt();
   2:             return new BigDecimal(value,scale);
   3:         }
   4:     }

View Full Code Here

BigDecimal

public 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. The value of the BigDecimal is (unscaledVal × 10-scale), rounded according to the precision and rounding mode settings.
Parameters:
unscaledVal - unscaled value of the BigDecimal.
scale - scale of the BigDecimal.
mc - the context to use.
Throws:
ArithmeticException - if the result is inexact but the rounding mode is UNNECESSARY.
Since:
1.5
Usages and Demos :

View More Examples of BigDecimal(BigInteger unscaledVal,int scale,MathContext mc)
   1:         try {
   2:             BigDecimal decimalNumber = new BigDecimal(number.replaceAll(",", ""));
   3:             if (decimalNumber.scale() == 0) {
   4:                 return formatNumber(decimalNumber.longValue());
   5:             } else {

View Full Code Here
   1:         }
   2:         return new java.math.BigDecimal(DateTimeUtil.diff(s,d1,d2));
   3:     }
   4:     
   5:     public static java.math.BigDecimal round(java.math.BigDecimal val,java.math.BigDecimal num){

View Full Code Here

BigDecimal

public BigDecimal(BigInteger val,
                  MathContext mc)
Translates a BigInteger into a BigDecimal rounding according to the context settings. The scale of the BigDecimal is zero.
Parameters:
val - BigInteger value to be converted to BigDecimal.
mc - the context to use.
Throws:
ArithmeticException - if the result is inexact but the rounding mode is UNNECESSARY.
Since:
1.5
Usages and Demos :

View More Examples of BigDecimal(BigInteger val,MathContext mc)
   1:         BigInteger bi = parseBigInteger(1,Integer.MAX_VALUE);
   2:         BigDecimal d = new BigDecimal(bi,vidx-s);
   3:         if( second==null)   second = d;
   4:         else                second = second.add(d);
   5:     }

View Full Code Here
   1:             BigDecimal bd = j == 0 ? BigDecimals.ZERO:
   2:                 new BigDecimal(j < 0 ? val: val.substring(0, j));
   3:             if (_scale != AUTO) bd = bd.setScale(_scale);
   4:             if (j <= 0) return bd;

View Full Code Here
   1:     List<BigDecimal> lbd = Arrays.asList(
   2:       new BigDecimal(1.1, mc), new BigDecimal(2.2, mc),
   3:         ...
   4:       new BigDecimal(3.3, mc), new BigDecimal(4.4, mc));
   5:     BigDecimal rbd = reduce(lbd, new BigDecimalAdder());
   6:     print(rbd);

View Full Code Here
   1:     BigInteger b = new BigInteger(s.toString());
   2:     BigDecimal dec = new BigDecimal(b, scale);
   3: 
   4:     return dec;
   5:   }

View Full Code Here
   1:             int scale = in.readInt();
   2:             return new BigDecimal(value,scale);
   3:         }
   4:     }

View Full Code Here

BigDecimal

public BigDecimal(long val)
Translates a long into a BigDecimal. The scale of the BigDecimal is zero.
Parameters:
val - long value to be converted to BigDecimal.
Since:
1.5
Usages and Demos :

View More Examples of BigDecimal(long val)
   1:         }
   2:         return (new BigDecimal(Double.toString(value.doubleValue()))).toString();
   3:     }
   4:         ...
   5:     public static final String toString(final double value) {
   6:         return (new BigDecimal("" + value)).toString();
   7:     }
   8: 

View Full Code Here
   1:     
   2:     public static final BigDecimal MAX_LONG = new BigDecimal("" + Long.MAX_VALUE);
   3:         ...
   4:     public static final BigDecimal MAX_INTEGER = new BigDecimal("" + Integer.MAX_VALUE);
   5:         ...
   6:     public static final BigDecimal MAX_SHORT = new BigDecimal("" + Short.MAX_VALUE);
   7:     public static final BigDecimal MAX_BYTE = new BigDecimal("" + Byte.MAX_VALUE);

View Full Code Here
   1:         }
   2:         return new BigDecimal(""+i);
   3:     }
   4:         ...
   5:         }
   6:         return new BigDecimal(""+i);
   7:     }
   8:     
   9:     

View Full Code Here

BigDecimal

public BigDecimal(long val,
                  MathContext mc)
Translates a long into a BigDecimal, with rounding according to the context settings. The scale of the BigDecimal, before any rounding, is zero.
Parameters:
val - long value to be converted to BigDecimal.
mc - the context to use.
Throws:
ArithmeticException - if the result is inexact but the rounding mode is UNNECESSARY.
Since:
1.5
Usages and Demos :

View More Examples of BigDecimal(long val,MathContext mc)
   1:         BigInteger bi = parseBigInteger(1,Integer.MAX_VALUE);
   2:         BigDecimal d = new BigDecimal(bi,vidx-s);
   3:         if( second==null)   second = d;
   4:         else                second = second.add(d);
   5:     }

View Full Code Here
   1:             BigDecimal bd = j == 0 ? BigDecimals.ZERO:
   2:                 new BigDecimal(j < 0 ? val: val.substring(0, j));
   3:             if (_scale != AUTO) bd = bd.setScale(_scale);
   4:             if (j <= 0) return bd;

View Full Code Here
   1:     List<BigDecimal> lbd = Arrays.asList(
   2:       new BigDecimal(1.1, mc), new BigDecimal(2.2, mc),
   3:         ...
   4:       new BigDecimal(3.3, mc), new BigDecimal(4.4, mc));
   5:     BigDecimal rbd = reduce(lbd, new BigDecimalAdder());
   6:     print(rbd);

View Full Code Here
   1:     BigInteger b = new BigInteger(s.toString());
   2:     BigDecimal dec = new BigDecimal(b, scale);
   3: 
   4:     return dec;
   5:   }

View Full Code Here
   1:             int scale = in.readInt();
   2:             return new BigDecimal(value,scale);
   3:         }
   4:     }

View Full Code Here

Method Details

abs

public BigDecimal abs()
Returns a BigDecimal whose value is the absolute value of this BigDecimal, and whose scale is this.scale().
Returns:
abs(this)
Usages and Demos :

View More Examples of abs()
   1: 
   2: import java.math.BigDecimal;
   3: 
   4:         ...
   5: 
   6:     protected Object performCalculation(BigDecimal value) {
   7:         ...
   8:         return value.abs();
   9:     }

View Full Code Here
   1: 
   2: import java.math.BigDecimal;
   3: import java.math.BigInteger;
   4:         ...
   5:     
   6:     BigDecimal value;
   7: 
   8:         ...
   9:     public DecimalValue(BigDecimal decimal) {
  10:         this.value = decimal;
  11:         ...
  12:             boolean negative = value.signum() < 0;
  13:             String s = value.abs().unscaledValue().toString();

View Full Code Here
   1:             else if (name.equals("C_DocType_ID"))
   2:                 p_C_DocType_ID = ((BigDecimal)para[i].getParameter()).intValue();
   3:             else if (name.equals("DatePromised"))
   4:         ...
   5:         MDistributionRunLine runLine = m_runLines[index];
   6:         BigDecimal difference = runLine.getActualAllocationDiff();
   7:         if (difference.compareTo(Env.ZERO) == 0)
   8:         ...
   9:             return;
  10:         boolean adjustBiggest = difference.abs().compareTo(Env.ONE) <= 0
  11:         ...
  12:             || difference.abs().compareTo(runLine.getLastDifference().abs()) == 0;

View Full Code Here

abs

public BigDecimal abs(MathContext mc)
Returns a BigDecimal whose value is the absolute value of this BigDecimal, with rounding according to the context settings.
Parameters:
mc - the context to use.
Returns:
abs(this), rounded as necessary.
Throws:
ArithmeticException - if the result is inexact but the rounding mode is UNNECESSARY.

add

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

View More Examples of add(BigDecimal augend)
   1: 
   2: import java.math.BigDecimal;
   3: 
   4:         ...
   5: 
   6:     protected Object performCalculation(BigDecimal value1, BigDecimal value2) {
   7:         ...
   8:         return value1.add(value2);
   9:     }

View Full Code Here
   1: import java.io.Serializable;
   2: import java.math.BigDecimal;
   3: 
   4:         ...
   5: {
   6:     private BigDecimal number1 = new BigDecimal(0);
   7:     private BigDecimal number2 = new BigDecimal(0);
   8:         ...
   9:     {
  10:         result = number1.add(number2);
  11:     }

View Full Code Here
   1: 
   2: import java.math.BigDecimal;
   3: 
   4:         ...
   5: 
   6:     protected BigDecimal _content;
   7: 
   8:         ...
   9:     {
  10:         BigDecimal givenValue = (BigDecimal)val.getContent();
  11: 
  12:         ...
  13:         BigDecimal result = _content.add(givenValue);

View Full Code Here
   1:             if (previousNumber.length() > 0 && currentNumber.length() > 0) {
   2:                 BigDecimal firstNumber = null;
   3:                 if (previousNumber.indexOf(".") == -1) {
   4:         ...
   5:                     firstNumber = new BigDecimal(previousNumber + ".0");
   6:                 }
   7:         ...
   8:                 else {
   9:                     firstNumber = new BigDecimal(previousNumber);
  10:                 }
  11:         ...
  12:                     case ADD_OPER:
  13:                         result = firstNumber.add(secondNumber);

View Full Code Here
   1: import java.rmi.RemoteException;
   2: import java.math.BigDecimal;
   3: 
   4:         ...
   5: public class AccountHistoryBean {
   6:    BigDecimal credits, debits, beginningBalance, endingBalance;
   7:    String accountId;
   8:         ...
   9:    public AccountHistoryBean () {
  10:     credits = new BigDecimal("0.00");
  11:     debits = new BigDecimal("0.00");
  12:         ...
  13:                if (amount.floatValue( ) < 0)
  14:                   credits.add(amount);

View Full Code Here

add

public BigDecimal add(BigDecimal augend,
                      MathContext mc)
Returns a BigDecimal whose value is (this + augend), with rounding according to the context settings. If either number is zero and the precision setting is nonzero then the other number, rounded if necessary, is used as the result.
Parameters:
augend - value to be added to this BigDecimal.
mc - the context to use.
Returns:
this + augend, rounded as necessary.
Throws:
ArithmeticException - if the result is inexact but the rounding mode is UNNECESSARY.
Since:
1.5

byteValueExact

public byte byteValueExact()
Converts this BigDecimal to a byte, checking for lost information. If this BigDecimal has a nonzero fractional part or is out of the possible range for a byte result then an ArithmeticException is thrown.
Returns:
this BigDecimal converted to a byte.
Throws:
ArithmeticException - if this has a nonzero fractional part, or will not fit in a byte.
Since:
1.5

compareTo

public int compareTo(BigDecimal val)
Compares this BigDecimal with the specified BigDecimal. Two BigDecimal objects 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.
Returns:
-1, 0, or 1 as this BigDecimal is numerically less than, equal to, or greater than val.
Usages and Demos :

View More Examples of compareTo(BigDecimal val)
   1: 
   2: import java.math.BigDecimal;
   3: 
   4:         ...
   5:     protected int compareNumbers(Number n1, Number n2) {
   6:         BigDecimal bd1 = new BigDecimal(n1.toString());
   7:         BigDecimal bd2 = new BigDecimal(n2.toString());
   8:         ...
   9:         return bd1.compareTo(bd2);
  10:     }

View Full Code Here
   1: import java.io.Serializable;
   2: import java.math.BigDecimal;
   3: import java.sql.Timestamp;
   4:         ...
   5:             String s = (String)cmp1;
   6:             return s.compareTo((String)cmp2) * m_multiplier;
   7:         }
   8:         ...
   9:             Timestamp t = (Timestamp)cmp1;
  10:             return t.compareTo((Timestamp)cmp2) * m_multiplier;
  11:         }
  12:         ...
  13:         else if (cmp1 instanceof BigDecimal && cmp2 instanceof BigDecimal)

View Full Code Here
   1: 
   2: import java.math.BigDecimal;
   3: import java.math.BigInteger;
   4:         ...
   5: 
   6:     private BigDecimal _value;
   7: 
   8:         ...
   9:         try {
  10:             set_BigDecimal(new BigDecimal(s));
  11:         }
  12:         ...
  13:     {
  14:         return _value.compareTo(((XmlObjectBase)decimal).bigDecimalValue());

View Full Code Here
   1: 
   2: import java.math.BigDecimal;
   3: import java.math.BigInteger;
   4:         ...
   5: 
   6:     private BigDecimal value;
   7: 
   8:         ...
   9: 
  10:     public DecimalValue(BigDecimal value) {
  11:         this.value = value;
  12:         ...
  13:         } else if (other instanceof BigIntegerValue) {
  14:             return value.compareTo(((BigIntegerValue)other).asDecimal());

View Full Code Here
   1: import java.beans.PropertyEditorManager;
   2: import java.math.BigDecimal;
   3: import java.math.BigInteger;
   4:         ...
   5:         if (isBigDecimalOp(obj0, obj1)) {
   6:             BigDecimal bd0 = (BigDecimal) coerceToNumber(obj0, BigDecimal.class);
   7:             BigDecimal bd1 = (BigDecimal) coerceToNumber(obj1, BigDecimal.class);
   8:         ...
   9:             return bd0.compareTo(bd1);
  10:         }
  11:         ...
  12:             Double d1 = (Double) coerceToNumber(obj1, Double.class);
  13:             return d0.compareTo(d1);

View Full Code Here

divide

public 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.
Parameters:
divisor - value by which this BigDecimal is to be divided.
Returns:
this / divisor
Throws:
ArithmeticException - if the exact quotient does not have a terminating decimal expansion
Since:
1.5
Usages and Demos :

View More Examples of divide(BigDecimal divisor)
   1:     private int            p_M_Product_To_ID = 0;
   2:     private BigDecimal    p_Qty = null;
   3: 
   4:         ...
   5:             else if (name.equals("Qty"))
   6:                 p_Qty = (BigDecimal)para[i].getParameter();
   7:             else
   8:         ...
   9:         MUOM uomTo = MUOM.get(getCtx(), productTo.getC_UOM_ID());
  10:         BigDecimal qtyTo = p_Qty.divide(conversion.getDivideRate(), uomTo.getStdPrecision(), BigDecimal.ROUND_HALF_UP);
  11:         ...
  12:         BigDecimal qtyTo6 = p_Qty.divide(conversion.getDivideRate(), 6, BigDecimal.ROUND_HALF_UP);

View Full Code Here
   1: 
   2: import java.math.BigDecimal;
   3: import java.math.BigInteger;
   4:         ...
   5: 
   6:     private BigDecimal value;
   7: 
   8:         ...
   9: 
  10:     public DecimalValue(BigDecimal value) {
  11:         this.value = value;
  12:         ...
  13:                                              Math.max(value.scale(), ((DecimalValue)other).value.scale()));
  14:                         BigDecimal result = value.divide(((DecimalValue)other).value, scale, BigDecimal.ROUND_HALF_DOWN);

View Full Code Here
   1: 
   2: import java.math.BigDecimal;
   3: import java.math.BigInteger;
   4:         ...
   5:     
   6:     BigDecimal value;
   7: 
   8:         ...
   9:     public DecimalValue(BigDecimal decimal) {
  10:         this.value = decimal;
  11:         ...
  12:                 int scale = Math.max(DIVIDE_PRECISION, Math.max(value.scale(), ((DecimalValue)other).value.scale()));
  13:                 BigDecimal result = value.divide(((DecimalValue)other).value, scale, BigDecimal.ROUND_HALF_DOWN);

View Full Code Here
   1: 
   2: import java.math.BigDecimal;
   3: import java.math.BigInteger;
   4:         ...
   5:                     throw new ExprEvalException("Divide by zero in divide") ;
   6:                 BigDecimal d1 = new BigDecimal(nv1.getInteger()) ;
   7:                 BigDecimal d2 = new BigDecimal(nv2.getInteger()) ;
   8:                 return NodeValue.makeDecimal(decimalDivide(d1, d2)) ;
   9:             }

View Full Code Here

divide

public BigDecimal divide(BigDecimal divisor,
                         int roundingMode)
Returns a BigDecimal whose value is (this / divisor), 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.

The new divide(BigDecimal,RoundingMode) method should be used in preference to this legacy method.

Parameters:
divisor - value by which this BigDecimal is to be divided.
roundingMode - rounding mode to apply.
Returns:
this / divisor
Throws:
ArithmeticException - if divisor==0, or roundingMode==ROUND_UNNECESSARY and this.scale() is insufficient to represent the result of the division exactly.
IllegalArgumentException - if roundingMode does not represent a valid rounding mode.
Usages and Demos :

View More Examples of divide(BigDecimal divisor,int roundingMode)
   1: 
   2: import java.math.BigDecimal;
   3: 
   4:         ...
   5: 
   6:     protected Object performCalculation(BigDecimal value1, BigDecimal value2) {
   7:         value1 = value1.abs();
   8:         ...
   9:         value2 = value2.abs();
  10:         BigDecimal quotient = value1.divide(value2, BigDecimal.ROUND_HALF_DOWN);
  11:         quotient = quotient.setScale(0, BigDecimal.ROUND_DOWN);

View Full Code Here
   1: import java.io.IOException;
   2: import java.math.BigDecimal;
   3: import java.math.BigInteger;
   4:         ...
   5: 
   6:     if (aObj instanceof BigDecimal
   7:         ...
   8:     || bObj instanceof BigDecimal
   9:     || aObj instanceof BigInteger
  10:         ...
  11:       
  12:       return a.divide(b, BigDecimal.ROUND_HALF_UP);

View Full Code Here
   1: import javax.servlet.jsp.el.ELException;
   2: import java.math.BigDecimal;
   3: 
   4:         ...
   5: 
   6:         BigDecimal left = (BigDecimal)
   7:             Coercions.coerceToPrimitiveNumber(pLeft, BigDecimal.class, pLogger);
   8:         ...
   9:         try {
  10:             return left.divide(right, BigDecimal.ROUND_HALF_UP);
  11:         } catch (Exception exc) {

View Full Code Here
   1: import java.lang.reflect.Array;
   2: import java.math.BigDecimal;
   3: import java.math.BigInteger;
   4:         ...
   5: 
   6:     protected Object op_bdec(BigDecimal d1, BigDecimal d2) {
   7:         throw new IllegalArgumentException(d1 + ", " + d2);
   8:         ...
   9:         public Object op_bdec(BigDecimal d1, BigDecimal d2) {
  10:             return d1.divide(d2, BigDecimal.ROUND_HALF_DOWN);
  11:         }

View Full Code Here

divide

public BigDecimal divide(BigDecimal divisor,
                         int scale,
                         int roundingMode)
Returns a BigDecimal whose value is (this / divisor), 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.

The new divide(BigDecimal,int,RoundingMode) method should be used in preference to this legacy method.

Parameters:
divisor - value by which this BigDecimal is to be divided.
scale - scale of the BigDecimal quotient to be returned.
roundingMode - rounding mode to apply.
Returns:
this / divisor
Throws:
ArithmeticException - if divisor is zero, roundingMode==ROUND_UNNECESSARY and the specified scale is insufficient to represent the result of the division exactly.
IllegalArgumentException - if roundingMode does not represent a valid rounding mode.
Usages and Demos :

View More Examples of divide(BigDecimal divisor,int scale,int roundingMode)
   1: 
   2: import java.math.BigDecimal;
   3: 
   4:         ...
   5: 
   6:     protected Object performCalculation(BigDecimal value1, BigDecimal value2) {
   7:         ...
   8:         return value1.divide(value2, 8, BigDecimal.ROUND_HALF_DOWN);
   9:     }

View Full Code Here
   1: import java.io.Serializable;
   2: import java.math.BigDecimal;
   3: import java.util.ArrayList;
   4:         ...
   5:     {
   6:         BigDecimal total = new BigDecimal(totalEditions);
   7:         BigDecimal page = new BigDecimal(pageSize);
   8:         ...
   9:         totalPages = Math.max(1, total.divide(page, 0, BigDecimal.ROUND_UP).intValue());
  10:         ...
  11:         currentPage = start.divide(page, 0, BigDecimal.ROUND_UP).intValue();

View Full Code Here
   1: 
   2: import java.math.BigDecimal;
   3: import java.math.BigInteger;
   4:         ...
   5:     
   6:     BigDecimal value;
   7: 
   8:         ...
   9:     public DecimalValue(BigDecimal decimal) {
  10:         this.value = decimal;
  11:         ...
  12:             throw new XPathException("FOAR0001: division by zero");
  13:         BigInteger quot = value.divide(dv.value, 0, BigDecimal.ROUND_DOWN).toBigInteger();

View Full Code Here
   1: 
   2: import java.math.BigDecimal;
   3: import java.math.BigInteger;
   4:         ...
   5:                     throw new ExprEvalException("Divide by zero in divide") ;
   6:                 BigDecimal d1 = new BigDecimal(nv1.getInteger()) ;
   7:                 BigDecimal d2 = new BigDecimal(nv2.getInteger()) ;
   8:         ...
   9:         try {
  10:             return d1.divide(d2, DIVIDE_PRECISION, BigDecimal.ROUND_FLOOR) ;
  11:         } catch (ArithmeticException ex)

View Full Code Here
   1: 
   2: import java.math.BigDecimal;
   3: import java.util.HashSet;
   4:         ...
   5: 
   6:     public static BigDecimal decimalDivide(BigDecimal arg1, BigDecimal arg2, int scale) {
   7:         ...
   8:         return arg1.divide(arg2, scale, BigDecimal.ROUND_DOWN);
   9:     }

View Full Code Here

divide

public BigDecimal divide(BigDecimal divisor,
                         int scale,
                         RoundingMode roundingMode)
Returns a BigDecimal whose value is (this / divisor), 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:
divisor - value by which this BigDecimal is to be divided.
scale - scale of the BigDecimal quotient to be returned.
roundingMode - rounding mode to apply.
Returns:
this / divisor
Throws:
ArithmeticException - if divisor is zero, roundingMode==RoundingMode.UNNECESSARY and the specified scale is insufficient to represent the result of the division exactly.
Since:
1.5
Usages and Demos :

View More Examples of divide(BigDecimal divisor,int scale,RoundingMode roundingMode)
   1: 
   2: import java.math.BigDecimal;
   3: 
   4:         ...
   5: 
   6:     protected Object performCalculation(BigDecimal value1, BigDecimal value2) {
   7:         ...
   8:         return value1.divide(value2, 8, BigDecimal.ROUND_HALF_DOWN);
   9:     }

View Full Code Here
   1: import java.io.Serializable;
   2: import java.math.BigDecimal;
   3: import java.util.ArrayList;
   4:         ...
   5:     {
   6:         BigDecimal total = new BigDecimal(totalEditions);
   7:         BigDecimal page = new BigDecimal(pageSize);
   8:         ...
   9:         totalPages = Math.max(1, total.divide(page, 0, BigDecimal.ROUND_UP).intValue());
  10:         ...
  11:         currentPage = start.divide(page, 0, BigDecimal.ROUND_UP).intValue();

View Full Code Here
   1: 
   2: import java.math.BigDecimal;
   3: import java.math.BigInteger;
   4:         ...
   5:     
   6:     BigDecimal value;
   7: 
   8:         ...
   9:     public DecimalValue(BigDecimal decimal) {
  10:         this.value = decimal;
  11:         ...
  12:             throw new XPathException("FOAR0001: division by zero");
  13:         BigInteger quot = value.divide(dv.value, 0, BigDecimal.ROUND_DOWN).toBigInteger();

View Full Code Here
   1: 
   2: import java.math.BigDecimal;
   3: import java.math.BigInteger;
   4:         ...
   5:                     throw new ExprEvalException("Divide by zero in divide") ;
   6:                 BigDecimal d1 = new BigDecimal(nv1.getInteger()) ;
   7:                 BigDecimal d2 = new BigDecimal(nv2.getInteger()) ;
   8:         ...
   9:         try {
  10:             return d1.divide(d2, DIVIDE_PRECISION, BigDecimal.ROUND_FLOOR) ;
  11:         } catch (ArithmeticException ex)

View Full Code Here
   1: 
   2: import java.math.BigDecimal;
   3: import java.util.HashSet;
   4:         ...
   5: 
   6:     public static BigDecimal decimalDivide(BigDecimal arg1, BigDecimal arg2, int scale) {
   7:         ...
   8:         return arg1.divide(arg2, scale, BigDecimal.ROUND_DOWN);
   9:     }

View Full Code Here

divide

public BigDecimal divide(BigDecimal divisor,
                         MathContext mc)
Returns a BigDecimal whose value is (this / divisor), with rounding according to the context settings.
Parameters:
divisor - value by which this BigDecimal is to be divided.
mc - the context to use.
Returns:
this / divisor, rounded as necessary.
Throws:
ArithmeticException - if the result is inexact but the rounding mode is UNNECESSARY or mc.precision == 0 and the quotient has a non-terminating decimal expansion.
Since:
1.5
Usages and Demos :

View More Examples of divide(BigDecimal divisor,MathContext mc)
   1: 
   2: import java.math.BigDecimal;
   3: 
   4:         ...
   5: 
   6:     protected Object performCalculation(BigDecimal value1, BigDecimal value2) {
   7:         value1 = value1.abs();
   8:         ...
   9:         value2 = value2.abs();
  10:         BigDecimal quotient = value1.divide(value2, BigDecimal.ROUND_HALF_DOWN);
  11:         quotient = quotient.setScale(0, BigDecimal.ROUND_DOWN);

View Full Code Here
   1: import java.io.IOException;
   2: import java.math.BigDecimal;
   3: import java.math.BigInteger;
   4:         ...
   5: 
   6:     if (aObj instanceof BigDecimal
   7:         ...
   8:     || bObj instanceof BigDecimal
   9:     || aObj instanceof BigInteger
  10:         ...
  11:       
  12:       return a.divide(b, BigDecimal.ROUND_HALF_UP);

View Full Code Here
   1: import javax.servlet.jsp.el.ELException;
   2: import java.math.BigDecimal;
   3: 
   4:         ...
   5: 
   6:         BigDecimal left = (BigDecimal)
   7:             Coercions.coerceToPrimitiveNumber(pLeft, BigDecimal.class, pLogger);
   8:         ...
   9:         try {
  10:             return left.divide(right, BigDecimal.ROUND_HALF_UP);
  11:         } catch (Exception exc) {

View Full Code Here
   1: import java.lang.reflect.Array;
   2: import java.math.BigDecimal;
   3: import java.math.BigInteger;
   4:         ...
   5: 
   6:     protected Object op_bdec(BigDecimal d1, BigDecimal d2) {
   7:         throw new IllegalArgumentException(d1 + ", " + d2);
   8:         ...
   9:         public Object op_bdec(BigDecimal d1, BigDecimal d2) {
  10:             return d1.divide(d2, BigDecimal.ROUND_HALF_DOWN);
  11:         }

View Full Code Here

divide

public BigDecimal divide(BigDecimal divisor,
                         RoundingMode roundingMode)
Returns a BigDecimal whose value is (this / divisor), 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:
divisor - value by which this BigDecimal is to be divided.
roundingMode - rounding mode to apply.
Returns:
this / divisor
Throws:
ArithmeticException - if divisor==0, or roundingMode==RoundingMode.UNNECESSARY and this.scale() is insufficient to represent the result of the division exactly.
Usages and Demos :

View More Examples of divide(BigDecimal divisor,RoundingMode roundingMode)
   1: 
   2: import java.math.BigDecimal;
   3: 
   4:         ...
   5: 
   6:     protected Object performCalculation(BigDecimal value1, BigDecimal value2) {
   7:         value1 = value1.abs();
   8:         ...
   9:         value2 = value2.abs();
  10:         BigDecimal quotient = value1.divide(value2, BigDecimal.ROUND_HALF_DOWN);
  11:         quotient = quotient.setScale(0, BigDecimal.ROUND_DOWN);

View Full Code Here
   1: import java.io.IOException;
   2: import java.math.BigDecimal;
   3: import java.math.BigInteger;
   4:         ...
   5: 
   6:     if (aObj instanceof BigDecimal
   7:         ...
   8:     || bObj instanceof BigDecimal
   9:     || aObj instanceof BigInteger
  10:         ...
  11:       
  12:       return a.divide(b, BigDecimal.ROUND_HALF_UP);

View Full Code Here
   1: import javax.servlet.jsp.el.ELException;
   2: import java.math.BigDecimal;
   3: 
   4:         ...
   5: 
   6:         BigDecimal left = (BigDecimal)
   7:             Coercions.coerceToPrimitiveNumber(pLeft, BigDecimal.class, pLogger);
   8:         ...
   9:         try {
  10:             return left.divide(right, BigDecimal.ROUND_HALF_UP);
  11:         } catch (Exception exc) {

View Full Code Here
   1: import java.lang.reflect.Array;
   2: import java.math.BigDecimal;
   3: import java.math.BigInteger;
   4:         ...
   5: 
   6:     protected Object op_bdec(BigDecimal d1, BigDecimal d2) {
   7:         throw new IllegalArgumentException(d1 + ", " + d2);
   8:         ...
   9:         public Object op_bdec(BigDecimal d1, BigDecimal d2) {
  10:             return d1.divide(d2, BigDecimal.ROUND_HALF_DOWN);
  11:         }

View Full Code Here

divideAndRemainder

public 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.

Note that if both the integer quotient and remainder are needed, this method is faster than using the divideToIntegralValue and remainder methods separately because the division need only be carried out once.

Parameters:
divisor - value by which this BigDecimal is to be divided, and the remainder computed.
Returns:
a two element BigDecimal array: the quotient (the result of divideToIntegralValue) is the initial element and the remainder is the final element.
Throws:
ArithmeticException - if divisor==0
Since:
1.5
Usages and Demos :

View More Examples of divideAndRemainder(BigDecimal divisor)
   1: 
   2: import java.math.BigDecimal;
   3: import java.math.BigInteger;
   4:         ...
   5:     public void testConstants() throws Exception {
   6:         assertEquals(0, BigDecimal.ZERO.intValue());
   7:         ...
   8:         assertEquals(1, BigDecimal.ONE.intValue());
   9:         assertEquals(10, BigDecimal.TEN.intValue());
  10:         ...
  11:         assertEquals(1, divisor.scale());
  12:         BigDecimal[] result = dividend.divideAndRemainder(divisor);

View Full Code Here

divideAndRemainder

public 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.

Note that if both the integer quotient and remainder are needed, this method is faster than using the divideToIntegralValue and remainder methods separately because the division need only be carried out once.

Parameters:
divisor - value by which this BigDecimal is to be divided, and the remainder computed.
mc - the context to use.
Returns:
a two element BigDecimal array: the quotient (the result of divideToIntegralValue) is the initial element and the remainder is the final element.
Throws:
ArithmeticException - if divisor==0
ArithmeticException - if the result is inexact but the rounding mode is UNNECESSARY, or mc.precision > 0 and the result of this.divideToIntgralValue(divisor) would require a precision of more than mc.precision digits.
Since:
1.5

divideToIntegralValue

public BigDecimal divideToIntegralValue(BigDecimal divisor)
Returns a BigDecimal whose value is the integer part of the quotient (this / divisor) rounded down. The preferred scale of the result is (this.scale() - divisor.scale()).
Parameters:
divisor - value by which this BigDecimal is to be divided.
Returns:
The integer part of this / divisor.
Throws:
ArithmeticException - if divisor==0
Since:
1.5
Usages and Demos :

View More Examples of divideToIntegralValue(BigDecimal divisor)
   1: 
   2: import java.math.BigDecimal;
   3: import java.math.BigInteger;
   4:         ...
   5:     public void testConstants() throws Exception {
   6:         assertEquals(0, BigDecimal.ZERO.intValue());
   7:         ...
   8:         assertEquals(1, BigDecimal.ONE.intValue());
   9:         assertEquals(10, BigDecimal.TEN.intValue());
  10:         ...
  11:         assertEquals(1, divisor.scale());
  12:         BigDecimal quotient = dividend.divideToIntegralValue(divisor);

View Full Code Here

divideToIntegralValue

public BigDecimal divideToIntegralValue(BigDecimal divisor,
                                        MathContext mc)
Returns a BigDecimal whose value is the integer part of (this / divisor). Since the integer part of the exact quotient does not depend on the rounding mode, the rounding mode does not affect the values returned by this method. The preferred scale of the result is (this.scale() - divisor.scale()). An ArithmeticException is thrown if the integer part of the exact quotient needs more than mc.precision digits.
Parameters:
divisor - value by which this BigDecimal is to be divided.
mc - the context to use.
Returns:
The integer part of this / divisor.
Throws:
ArithmeticException - if divisor==0
ArithmeticException - if mc.precision > 0 and the result requires a precision of more than mc.precision digits.
Since:
1.5

doubleValue

public double doubleValue()
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.
Overrides:
doubleValue in interface Number
Returns:
this BigDecimal converted to a double.
Usages and Demos :

View More Examples of doubleValue()
   1: 
   2: import java.math.BigDecimal;
   3: import java.math.BigInteger;
   4:         ...
   5: 
   6:   private final BigDecimal _val;
   7: 
   8:         ...
   9:   public BigDecimalValue(Env env, BigDecimal val, JavaClassDef def)
  10:   {
  11:         ...
  12:   {
  13:     return _val.doubleValue();

View Full Code Here
   1: 
   2: import java.math.BigDecimal;
   3: 
   4:         ...
   5: {
   6:     BigDecimal decimal ;
   7:     
   8:         ...
   9:     public NodeValueDecimal(BigDecimal d)         { decimal = d ; }
  10:     public NodeValueDecimal(BigDecimal d, Node n) { super(n) ; decimal = d ; }
  11:         ...
  12:     public float getFloat()    { return decimal.floatValue() ; }
  13:     public double getDouble()  { return decimal.doubleValue() ; }

View Full Code Here
   1:   int languageId;
   2:   BigDecimal price;
   3:   String coverImageFileSpec;
   4:         ...
   5: 
   6:     price = new BigDecimal(data.getProperty("price"));
   7:         ...
   8:     ps.setDouble(7, price.doubleValue());

View Full Code Here
   1: 
   2: import java.math.BigDecimal;
   3: 
   4:         ...
   5: 
   6:    protected static BigDecimal acos(final BigDecimal bd)
   7:          throws OperationException {
   8:         ...
   9:       double errorCheckingDouble = bd.doubleValue();
  10: 
  11:         ...
  12:          throws OperationException {
  13:       double errorCheckingDouble = bd.doubleValue();

View Full Code Here
   1: import java.io.File;
   2: import java.math.BigDecimal;
   3: import java.text.MessageFormat;
   4:         ...
   5:             UserData user = rreq.getUser();
   6:             BigDecimal maxDirMB = rollerConfig.getUploadMaxDirMB();
   7:         ...
   8:             int maxDirBytes = (int)(1024000 * maxDirMB.doubleValue());
   9: 
  10:         ...
  11:             {
  12:                 BigDecimal maxFileMB = rollerConfig.getUploadMaxFileMB();

View Full Code Here

equals

public boolean equals(Object x)
Compares this BigDecimal with the specified Object for equality. Unlike compareTo, this method considers two BigDecimal objects equal only if they are equal in value and scale (thus 2.0 is not equal to 2.00 when compared by this method).
Overrides:
equals in interface Object
Parameters:
x - Object to which this BigDecimal is to be compared.
Returns:
true if and only if the specified Object is a BigDecimal whose value and scale are equal to this BigDecimal's.
Usages and Demos :

View More Examples of equals(Object x)
   1: 
   2: import java.math.BigDecimal;
   3: import java.util.Date;
   4:         ...
   5:     public float      type_float;
   6:     public BigDecimal type_bigDecimal;
   7:     public byte       type_byte;
   8:         ...
   9:         if ((type_string != null) && (root.type_string != null))
  10:             result &= (type_string.equals(root.type_string));
  11:         else
  12:         ...
  13:         if ((type_bigDecimal != null) && (root.type_bigDecimal != null))
  14:             result &= (type_bigDecimal.equals(root.type_bigDecimal));

View Full Code Here
   1: 
   2: import java.math.BigDecimal;
   3: 
   4:         ...
   5:     private int _s;
   6:     private BigDecimal _fs;
   7: 
   8:         ...
   9:                 while (i < len && GDate.isDigit(ch = str.charAt(i)));
  10:                 _fs = new BigDecimal(str.subSequence(start, i).toString());
  11:                 if (i >= len || ch != 'S')
  12:         ...
  13:                 _s == duration.getSecond() &&
  14:                 _fs.equals(duration.getFraction()));

View Full Code Here
   1: import java.beans.PropertyEditorManager;
   2: import java.math.BigDecimal;
   3: import java.math.BigInteger;
   4:         ...
   5:         if (isBigDecimalOp(obj0, obj1)) {
   6:             BigDecimal bd0 = (BigDecimal) coerceToNumber(obj0, BigDecimal.class);
   7:             BigDecimal bd1 = (BigDecimal) coerceToNumber(obj1, BigDecimal.class);
   8:         ...
   9:         if (obj0 instanceof Boolean || obj1 instanceof Boolean) {
  10:             return coerceToBoolean(obj0).equals(coerceToBoolean(obj1));
  11:         }
  12:         ...
  13:         if (obj0 instanceof String || obj1 instanceof String) {
  14:             return coerceToString(obj0).equals(coerceToString(obj1));

View Full Code Here
   1: import java.beans.PropertyEditorManager;
   2: import java.math.BigDecimal;
   3: import java.math.BigInteger;
   4:         ...
   5:         if (isBigDecimalOp(obj0, obj1)) {
   6:             BigDecimal bd0 = (BigDecimal) coerceToNumber(obj0, BigDecimal.class);
   7:             BigDecimal bd1 = (BigDecimal) coerceToNumber(obj1, BigDecimal.class);
   8:         ...
   9:         } else if (obj0 instanceof Boolean || obj1 instanceof Boolean) {
  10:             return coerceToBoolean(obj0).equals(coerceToBoolean(obj1));
  11:         } else if (obj0.getClass().isEnum()) {
  12:         ...
  13:             BigDecimal bd1 = (BigDecimal) coerceToNumber(obj1, BigDecimal.class);
  14:             return bd0.equals(bd1);

View Full Code Here

floatValue

public float floatValue()
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.
Overrides:
floatValue in interface Number
Returns:
this BigDecimal converted to a float.
Usages and Demos :

View More Examples of floatValue()
   1: 
   2: import java.math.BigDecimal;
   3: 
   4:         ...
   5: {
   6:     BigDecimal decimal ;
   7:     
   8:         ...
   9:     public NodeValueDecimal(BigDecimal d)         { decimal = d ; }
  10:     public NodeValueDecimal(BigDecimal d, Node n) { super(n) ; decimal = d ; }
  11:         ...
  12:     public BigDecimal getDecimal()  { return decimal ; }
  13:     public float getFloat()    { return decimal.floatValue() ; }

View Full Code Here
   1: import java.util.List;
   2: import java.math.BigDecimal;
   3: 
   4:         ...
   5:     float x = ((Verbindung)netzwerk.getVerbindungenListe().get(0)).getSize();
   6:     BigDecimal bd = new BigDecimal(netzwerk.getTimer().getCurrentTime());
   7:     bd = bd.setScale(4, BigDecimal.ROUND_HALF_EVEN);
   8:   }
   9:   public int getValuation()

View Full Code Here
   1: import java.sql.SQLException;
   2: import java.math.BigDecimal;
   3: 
   4:         ...
   5: 
   6:         if (value.floatValue() > MAX_BYTE_VALUE ||
   7:         ...
   8:             value.floatValue() < MIN_BYTE_VALUE)
   9:                 throw (SQLException)createException(
  10:         ...
  11: 
  12:         if (value.floatValue() > MAX_SHORT_VALUE ||

View Full Code Here
   1: 
   2: import java.math.BigDecimal;
   3: import java.rmi.RemoteException;
   4:         ...
   5:             Integer result = null;
   6:             if (dto.getAmount().floatValue() > 0) {
   7:                 result = bl.processPayment(entityId, dto);
   8:         ...
   9:                 CreateException, RemoveException, SQLException {
  10:         BigDecimal totalPaid = new BigDecimal(0);
  11:         if (invoice != null) {
  12:         ...
  13:                 if (balance != null) {
  14:                     boolean balanceSign = (balance.floatValue() < 0) ? 

View Full Code Here
   1: import java.math.BigInteger;
   2: import java.math.BigDecimal;
   3: import java.io.Serializable;
   4:         ...
   5:     public float floatValue()
   6:         { BigDecimal bd = bigDecimalValue(); return bd == null ? 0.0f : bd.floatValue(); }
   7:     public double doubleValue()
   8:         ...
   9:         { BigDecimal bd = bigDecimalValue(); return bd == null ? 0.0 : bd.doubleValue(); }
  10:     public BigDecimal bigDecimalValue()

View Full Code Here

hashCode

public int hashCode()
Returns the hash code for this BigDecimal. Note that two BigDecimal objects that are numerically equal but differ in scale (like 2.0 and 2.00) will generally not have the same hash code.
Overrides:
hashCode in interface Object
Returns:
hash code for this BigDecimal.
Usages and Demos :

View More Examples of hashCode()
   1: import java.io.Serializable;
   2: import java.math.BigDecimal;
   3: 
   4:         ...
   5:     private static Object NULL_UNIT_OF_MEASURE = new Object();
   6:     public static Quantity ZERO = new Quantity(new BigDecimal(0), null);
   7: 
   8:         ...
   9:     protected BigDecimal magnitude;
  10:     protected Object unitOfMeasure;
  11:         ...
  12:     public int hashCode() {
  13:         return magnitude.hashCode();

View Full Code Here
   1: import java.io.Serializable;
   2: import java.math.BigDecimal;
   3: 
   4:         ...
   5: 
   6:     private BigDecimal amount;
   7: 
   8:         ...
   9:         if (amount != null)
  10:             this.amount = init(new BigDecimal(amount));
  11:         else
  12:         ...
  13: 
  14:         return amount.hashCode();

View Full Code Here

intValue

public int intValue()
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 this BigDecimal value as well as return a result with the opposite sign.
Overrides:
intValue in interface Number
Returns:
this BigDecimal converted to an int.
Usages and Demos :

View More Examples of intValue()
   1: {
   2:     private BigDecimal    m_AD_Table_ID;
   3: 
   4:         ...
   5:             else if (name.equals("AD_PrintFormat_ID"))
   6:                 m_AD_PrintFormat_ID = ((BigDecimal)para[i].getParameter());
   7:             else if (name.equals("AD_Table_ID"))
   8:         ...
   9:                 m_AD_Table_ID = ((BigDecimal)para[i].getParameter());
  10:             else
  11:         ...
  12:     {
  13:         if (m_AD_Table_ID != null && m_AD_Table_ID.intValue() > 0)

View Full Code Here
   1: 
   2: import java.math.BigDecimal;
   3: 
   4:         ...
   5: 
   6:     protected BigDecimal _content;
   7: 
   8:         ...
   9:         
  10:         return _content.intValue();    
  11:     }
  12:         ...
  13:     {
  14:         BigDecimal givenValue = (BigDecimal)val.getContent();

View Full Code Here
   1:         if (m_Parameter instanceof Number)
   2:             return ((Number)m_Parameter).intValue();
   3:         ...
   4:         BigDecimal bd = new BigDecimal(m_Parameter.toString());
   5:         ...
   6:         return bd.intValue();
   7: 
   8:         ...
   9:         if (m_Parameter_To instanceof Number)
  10:             return ((Number)m_Parameter_To).intValue();

View Full Code Here
   1: import java.io.IOException;
   2: import java.math.BigDecimal;
   3: import java.util.Iterator;
   4:         ...
   5:          if (share.getShareType() == null) {
   6:             share.setShareType(new java.math.BigDecimal(0));
   7:          }
   8:         ...
   9:                                                   element.getMapping_id(),
  10:                                                   new BigDecimal(entryId).intValue());
  11:                }
  12:         ...
  13:                for (int j = 0; j < mappings.length; j++) {
  14:                   BigDecimal entryId = new BigDecimal(mappings[j]);

View Full Code Here
   1: 
   2: import java.math.BigDecimal;
   3: import java.math.BigInteger;
   4:         ...
   5:     }
   6:     public BigDecimal bigDecimalValue() { check_dated(); return new BigDecimal(_value); }
   7:     public BigInteger bigIntegerValue() { check_dated(); return BigInteger.valueOf(_value); }
   8:         ...
   9:             throw new XmlValueOutOfRangeException();
  10:         set_int(v.intValue());
  11:     }
  12:         ...
  13: 
  14:         return _value == ((XmlObjectBase)i).intValue() ? 0 :

View Full Code Here

intValueExact

public int intValueExact()
Converts this BigDecimal to an int, checking for lost information. If this BigDecimal has a nonzero fractional part or is out of the possible range for an int result then an ArithmeticException is thrown.
Returns:
this BigDecimal converted to an int.
Throws:
ArithmeticException - if this has a nonzero fractional part, or will not fit in an int.
Since:
1.5

longValue

public long longValue()
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 this BigDecimal value as well as return a result with the opposite sign.
Overrides:
longValue in interface Number
Returns:
this BigDecimal converted to a long.
Usages and Demos :

View More Examples of longValue()
   1: 
   2: import java.math.BigDecimal;
   3: import java.math.BigInteger;
   4:         ...
   5: 
   6:   private final BigDecimal _val;
   7: 
   8:         ...
   9:   public BigDecimalValue(Env env, BigDecimal val, JavaClassDef def)
  10:   {
  11:         ...
  12:   {
  13:     return _val.longValue();

View Full Code Here
   1: import java.sql.SQLException;
   2: import java.math.BigDecimal;
   3: 
   4:         ...
   5: 
   6:         return value.longValue();
   7:     }
   8:         ...
   9:     }
  10:     public BigDecimal getBigDecimal() throws SQLException {
  11:         if (getFieldData()==null) return BIGDECIMAL_NULL_VALUE;
  12:         ...
  13: 
  14:         return new BigDecimal(field.decodeFloat(getFieldData()));

View Full Code Here
   1: import java.sql.SQLException;
   2: import java.math.BigDecimal;
   3: import java.math.BigInteger;
   4:         ...
   5: 
   6:         BigDecimal value = getBigDecimal();
   7:         
   8:         ...
   9:         
  10:         BigDecimal value = getBigDecimal();
  11:         
  12:         ...
  13:         
  14:         return value.longValue();

View Full Code Here
   1: 
   2: import java.math.BigDecimal;
   3: import java.sql.Timestamp;
   4:         ...
   5:                     .getTableProxyRMI("SPIN_DOCUMENT");
   6:             this.minObjectID = new BigDecimal(Long.MIN_VALUE);
   7:         } catch (Exception x) {
   8:         ...
   9:             sqlQueryString += "where SUBMITTED = 'SpinNode' and OBJECT_ID > "
  10:                     + this.minObjectID.longValue();
  11:             TableProxy searchResultsTable = this.dbFactory
  12:         ...
  13:             nextRecord = searchResultsTable.getRecordProxy(1);
  14:             BigDecimal oid = (BigDecimal) nextRecord

View Full Code Here
   1: import java.math.BigInteger;
   2: import java.math.BigDecimal;
   3: 
   4:         ...
   5: 
   6:   public static Rational valueOf(BigDecimal n) {
   7:     Rational r = new Rational(n.unscaledValue(), BIG_TEN.pow(n.scale()));
   8:         ...
   9:         (n instanceof Short) || (n instanceof Byte)) {
  10:       return valueOf(n.longValue());
  11: 
  12:         ...
  13: 
  14:     } else if (n instanceof BigDecimal) {

View Full Code Here

longValueExact

public long longValueExact()
Converts this BigDecimal to a long, checking for lost information. If this BigDecimal has a nonzero fractional part or is out of the possible range for a long result then an ArithmeticException is thrown.
Returns:
this BigDecimal converted to a long.
Throws:
ArithmeticException - if this has a nonzero fractional part, or will not fit in a long.
Since:
1.5

max

public BigDecimal max(BigDecimal val)
Returns the maximum of this BigDecimal and val.
Parameters:
val - value with which the maximum is to be computed.
Returns:
the BigDecimal whose value is the greater of this BigDecimal and val. If they are equal, as defined by the compareTo method, this is returned.
Usages and Demos :

View More Examples of max(BigDecimal val)
   1: 
   2: import java.math.BigDecimal;
   3: import java.math.BigInteger;
   4:         ...
   5:     
   6:     BigDecimal value;
   7: 
   8:         ...
   9:     public DecimalValue(BigDecimal decimal) {
  10:         this.value = decimal;
  11:         ...
  12:             default: 
  13:                 int scale = Math.max(DIVIDE_PRECISION, Math.max(value.scale(), ((DecimalValue)other).value.scale()));

View Full Code Here

min

public BigDecimal min(BigDecimal val)
Returns the minimum of this BigDecimal and val.
Parameters:
val - value with which the minimum is to be computed.
Returns:
the BigDecimal whose value is the lesser of this BigDecimal and val. If they are equal, as defined by the compareTo method, this is returned.
Usages and Demos :

View More Examples of min(BigDecimal val)
   1: 
   2: import java.math.BigDecimal;
   3: import java.math.BigInteger;
   4:         ...
   5:     
   6:     BigDecimal value;
   7: 
   8:         ...
   9:     public DecimalValue(BigDecimal decimal) {
  10:         this.value = decimal;
  11:         ...
  12:         if (other.getType() == Type.DECIMAL) {
  13:             return new DecimalValue(value.min(((DecimalValue) other).value));

View Full Code Here

movePointLeft

public BigDecimal movePointLeft(int n)
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.
Returns:
a BigDecimal which is equivalent to this one with the decimal point moved n places to the left.
Throws:
ArithmeticException - if scale overflows.

movePointRight

public BigDecimal movePointRight(int n)
Returns a BigDecimal which is equivalent to this one with the decimal point moved n places to the right. If n is non-negative, the call merely subtracts n from the 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.
Returns:
a BigDecimal which is equivalent to this one with the decimal point moved n places to the right.
Throws:
ArithmeticException - if scale overflows.
Usages and Demos :

View More Examples of movePointRight(int n)
   1: 
   2: import java.math.BigDecimal;
   3: 
   4:         ...
   5:   boolean satisfiesRestriction(Object obj) {
   6:     return getPrecision((BigDecimal)obj) <= precision;
   7:   }
   8:         ...
   9: 
  10:   static int getPrecision(BigDecimal n) {
  11:         ...
  12:     return n.movePointRight(n.scale()).abs().toString().length();

View Full Code Here
   1: 
   2: import java.math.BigDecimal;
   3: import java.text.SimpleDateFormat;
   4:         ...
   5:     if (m.group(8) != null && m.group(8).length() > 0) {
   6:       final BigDecimal bd = new BigDecimal("0." + m.group(8));
   7:         ...
   8:       dateTime.set(Calendar.MILLISECOND, bd.movePointRight(3).intValue());
   9:     }

View Full Code Here
   1: 
   2: import java.math.BigDecimal;
   3: import java.math.BigInteger;
   4:         ...
   5:     
   6:     BigDecimal value;
   7: 
   8:         ...
   9:     public DecimalValue(BigDecimal decimal) {
  10:         this.value = decimal;
  11:         ...
  12:             return new DecimalValue(
  13:                         value.movePointRight(pre).

View Full Code Here
   1: import java.io.Serializable;
   2: import java.math.BigDecimal;
   3: import java.math.BigInteger;
   4:         ...
   5:     
   6:     private BigDecimal fractionalSecond = null;
   7: 
   8:         ...
   9:         int second,
  10:         BigDecimal fractionalSecond,
  11:         int timezone) {
  12:         ...
  13:         else {
  14:             return fractionalSecond.movePointRight(3).intValue();

View Full Code Here

multiply

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

View More Examples of multiply(BigDecimal multiplicand)
   1: 
   2: import java.math.BigDecimal;
   3: 
   4:         ...
   5: 
   6:     protected Object performCalculation(BigDecimal value1, BigDecimal value2) {
   7:         ...
   8:         return value1.multiply(value2);
   9:     }

View Full Code Here
   1:     {
   2:         BigDecimal subTotal, salesTax, invoiceTotal;
   3:         ...
   4:         BigDecimal taxRate = new BigDecimal("0.05");
   5: 
   6:         ...
   7: 
   8:             salesTax = subTotal.multiply(taxRate);
   9:             salesTax = salesTax.setScale(2, RoundingMode.HALF_UP);

View Full Code Here
   1:     
   2:     public BigDecimal getAmt()
   3:     {
   4:         ...
   5:         BigDecimal amt = Env.ZERO;
   6:         getShipLine();
   7:         ...
   8:         }
   9:         return amt.multiply(getQty());
  10:     

View Full Code Here
   1:     private static final int roundingMode = 
   2:         BigDecimal.ROUND_HALF_EVEN;
   3: 
   4:         ...
   5: 
   6:     public static BigDecimal computePi(int digits) {
   7:         int scale = digits + 5;
   8:         ...
   9:         BigDecimal arctan1_5 = arctan(5, scale);
  10:         BigDecimal arctan1_239 = arctan(239, scale);
  11:         ...
  12:         BigDecimal pi = arctan1_5.multiply(FOUR).subtract(

View Full Code Here
   1: {
   2:     private BigDecimal        p_Qty;
   3:     private int                p_Bill_BPartner_ID;
   4:         ...
   5:             else if (name.equals("Qty"))
   6:                 p_Qty = (BigDecimal)para[i].getParameter();
   7:             else if (name.equals("IsCreateSingleOrder"))
   8:         ...
   9:         }
  10:         BigDecimal ratio = dll.getRatio();
  11:         ...
  12:         BigDecimal qty = p_Qty.multiply(ratio);

View Full Code Here

multiply

public BigDecimal multiply(BigDecimal multiplicand,
                           MathContext mc)
Returns a BigDecimal whose value is (this × multiplicand), with rounding according to the context settings.
Parameters:
multiplicand - value to be multiplied by this BigDecimal.
mc - the context to use.
Returns:
this * multiplicand, rounded as necessary.
Throws:
ArithmeticException - if the result is inexact but the rounding mode is UNNECESSARY.
Since:
1.5

negate

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

View More Examples of negate()
   1: 
   2: import java.math.BigDecimal;
   3: import java.math.BigInteger;
   4:         ...
   5:             return new Double(-valueAsDouble);
   6:         } else if (val instanceof BigDecimal) {
   7:         ...
   8:             BigDecimal valueAsBigD = (BigDecimal) val;
   9:         ...
  10:             return valueAsBigD.negate();

View Full Code Here
   1: import java.math.BigInteger;
   2: import java.math.BigDecimal;
   3: import java.util.Calendar;
   4:         ...
   5:     private final BigInteger minutes;
   6:     private final BigDecimal seconds;
   7: 
   8:         ...
   9:              BigInteger years, BigInteger months, BigInteger days,
  10:              BigInteger hours, BigInteger minutes, BigDecimal seconds) {
  11:       if (negative) {
  12:         ...
  13:         this.years = years.negate();

View Full Code Here
   1:             {
   2:                 BigDecimal qtyDiff = line.getQtyInternalUse().negate();
   3:                 if (qtyDiff.signum() == 0)
   4:         ...
   5:                             line.getM_Product_ID(), 0, get_TrxName());
   6:                     BigDecimal qtyNew = storage.getQtyOnHand().add(qtyDiff);
   7:                     log.fine("Diff=" + qtyDiff 
   8:         ...
   9:                                 line.getM_Product_ID(), ma.getM_AttributeSetInstance_ID(), get_TrxName());
  10:                         BigDecimal maxDiff = qtyDiff;
  11:                         if (maxDiff.signum() < 0 
  12:         ...
  13:                             && ma.getMovementQty().compareTo(maxDiff.negate()) < 0)

View Full Code Here
   1:         
   2:         m_Amount = (BigDecimal)m_mTab.getValue("GrandTotal");
   3:         if (!m_onlyRule && m_Amount.compareTo(Env.ZERO) == 0)
   4:         ...
   5:             KeyNamePair pp = (KeyNamePair)sCurrencyCombo.getSelectedItem();
   6:             BigDecimal amt = MConversionRate.convert(Env.getCtx(),
   7:                 m_Amount, m_C_Currency_ID, pp.getKey(), m_AD_Client_ID, m_AD_Org_ID);
   8:         ...
   9:             KeyNamePair pp = (KeyNamePair)bCurrencyCombo.getSelectedItem();
  10:             BigDecimal amt = MConversionRate.convert(Env.getCtx(),
  11:                 m_Amount, m_C_Currency_ID, pp.getKey(), m_AD_Client_ID, m_AD_Org_ID);
  12:         ...
  13:         if (negateAmt)
  14:             payAmount = m_Amount.negate();

View Full Code Here
   1:     
   2:     public BigDecimal getGrandTotal (boolean creditMemoAdjusted)
   3:     {
   4:         ...
   5:             return super.getGrandTotal();
   6:         BigDecimal amt = getGrandTotal();
   7:         if (isCreditMemo())
   8:         ...
   9:             return amt.negate();
  10:         return amt;
  11:         ...
  12:         }
  13:         BigDecimal total = Env.ZERO;

View Full Code Here

negate

public BigDecimal negate(MathContext mc)
Returns a BigDecimal whose value is (-this), with rounding according to the context settings.
Parameters:
mc - the context to use.
Returns:
-this, rounded as necessary.
Throws:
ArithmeticException - if or the result is inexact but the rounding mode is UNNECESSARY.
Since:
1.5

plus

public BigDecimal plus()
Returns a BigDecimal whose value is (+this), and whose scale is this.scale().

This method, which simply returns this BigDecimal is included for symmetry with the unary minus method negate().

Returns:
this.
Since:
1.5
See Also:
negate()

plus

public BigDecimal plus(MathContext mc)
Returns a BigDecimal whose value is (+this), with rounding according to the context settings.

The effect of this method is identical to that of the round(MathContext) method.

Parameters:
mc - the context to use.
Returns:
this, rounded as necessary. A zero result will have a scale of 0.
Throws:
ArithmeticException - if the result is inexact but the rounding mode is UNNECESSARY.
Since:
1.5

pow

public BigDecimal pow(int n)
Returns a BigDecimal whose value is (thisn), The power is computed exactly, to unlimited precision.

The parameter n must be in the range 0 through 999999999, inclusive. ZERO.pow(0) returns ONE. Note that future releases may expand the allowable exponent range of this method.

Parameters:
n - power to raise this BigDecimal to.
Returns:
thisn
Throws:
ArithmeticException - if n is out of range.
Since:
1.5

pow

public BigDecimal pow(int n,
                      MathContext mc)
Returns a BigDecimal whose value is (thisn). The current implementation uses the core algorithm defined in ANSI standard X3.274-1996 with rounding according to the context settings. In general, the returned numerical value is within two ulps of the exact numerical value for the chosen precision. Note that future releases may use a different algorithm with a decreased allowable error bound and increased allowable exponent range.

The X3.274-1996 algorithm is:

  • An ArithmeticException exception is thrown if
    • abs(n) > 999999999
    • mc.precision == 0 and n < 0
    • mc.precision > 0 and n has more than mc.precision decimal digits
  • if n is zero, ONE is returned even if this is zero, otherwise
    • if n is positive, the result is calculated via the repeated squaring technique into a single accumulator. The individual multiplications with the accumulator use the same math context settings as in mc except for a precision increased to mc.precision + elength + 1 where elength is the number of decimal digits in n.
    • if n is negative, the result is calculated as if n were positive; this value is then divided into one using the working precision specified above.
    • The final value from either the positive or negative case is then rounded to the destination precision.
  • Parameters:
    n - power to raise this BigDecimal to.
    mc - the context to use.
    Returns:
    thisn using the ANSI standard X3.274-1996 algorithm
    Throws:
    ArithmeticException - if the result is inexact but the rounding mode is UNNECESSARY, or n is out of range.
    Since:
    1.5

    precision

    public int precision()
    Returns the precision of this BigDecimal. (The precision is the number of digits in the unscaled value.)

    The precision of a zero value is 1.

    Returns:
    the precision of this BigDecimal.
    Since:
    1.5
    Usages and Demos :

    View More Examples of precision()
       1: import org.geotools.xml.SimpleBinding;
       2: import java.math.BigDecimal;
       3: import java.util.Calendar;
       4:         ...
       5:     public Class getType() {
       6:         return BigDecimal.class;
       7:     }
       8:         ...
       9: 
      10:         BigDecimal decimal = new BigDecimal(text);
    

    View Full Code Here

    remainder

    public BigDecimal remainder(BigDecimal divisor)
    Returns a BigDecimal whose value is (this % divisor).

    The remainder is given by this.subtract(this.divideToIntegralValue(divisor).multiply(divisor)). Note that this is not the modulo operation (the result can be negative).

    Parameters:
    divisor - value by which this BigDecimal is to be divided.
    Returns:
    this % divisor.
    Throws:
    ArithmeticException - if divisor==0
    Since:
    1.5
    Usages and Demos :

    View More Examples of remainder(BigDecimal divisor)
       1: 
       2: import java.math.BigDecimal;
       3: import java.math.BigInteger;
       4:         ...
       5:     public void testConstants() throws Exception {
       6:         assertEquals(0, BigDecimal.ZERO.intValue());
       7:         ...
       8:         assertEquals(1, BigDecimal.ONE.intValue());
       9:         assertEquals(10, BigDecimal.TEN.intValue());
      10:         ...
      11:         assertEquals(4, divisor.scale());
      12:         BigDecimal remainder = dividend.remainder(divisor);

    View Full Code Here

    remainder

    public BigDecimal remainder(BigDecimal divisor,
                                MathContext mc)
    Returns a BigDecimal whose value is (this % divisor), with rounding according to the context settings. The MathContext settings affect the implicit divide used to compute the remainder. The remainder computation itself is by definition exact. Therefore, the remainder may contain more than mc.getPrecision() digits.

    The remainder is given by this.subtract(this.divideToIntegralValue(divisor, mc).multiply(divisor)). Note that this is not the modulo operation (the result can be negative).

    Parameters:
    divisor - value by which this BigDecimal is to be divided.
    mc - the context to use.
    Returns:
    this % divisor, rounded as necessary.
    Throws:
    ArithmeticException - if divisor==0
    ArithmeticException - if the result is inexact but the rounding mode is UNNECESSARY, or mc.precision > 0 and the result of this.divideToIntgralValue(divisor) would require a precision of more than mc.precision digits.
    Since:
    1.5

    round

    public BigDecimal round(MathContext mc)
    Returns a BigDecimal rounded according to the MathContext settings. If the precision setting is 0 then no rounding takes place.

    The effect of this method is identical to that of the plus(MathContext) method.

    Parameters:
    mc - the context to use.
    Returns:
    a BigDecimal rounded according to the MathContext settings.
    Throws:
    ArithmeticException - if the rounding mode is UNNECESSARY and the BigDecimal operation would require rounding.
    Since:
    1.5

    scale

    public int scale()
    Returns the scale of this BigDecimal. If zero or positive, the scale is the number of digits to the right of the decimal point. If negative, the unscaled value of the number is multiplied by ten to the power of the negation of the scale. For example, a scale of -3 means the unscaled value is multiplied by 1000.
    Returns:
    the scale of this BigDecimal.
    Usages and Demos :

    View More Examples of scale()
       1: 
       2: import java.math.BigDecimal;
       3: 
       4:         ...
       5:   boolean satisfiesRestriction(Object obj) {
       6:     return getPrecision((BigDecimal)obj) <= precision;
       7:   }
       8:         ...
       9: 
      10:   static int getPrecision(BigDecimal n) {
      11:         ...
      12:     return n.movePointRight(n.scale()).abs().toString().length();

    View Full Code Here
       1: 
       2: import java.math.BigDecimal;
       3: 
       4:         ...
       5: {
       6:     BigDecimal decimal ;
       7:     
       8:         ...
       9:     public NodeValueDecimal(BigDecimal d)         { decimal = d ; }
      10:     public NodeValueDecimal(BigDecimal d, Node n) { super(n) ; decimal = d ; }
      11:         ...
      12:     { 
      13:         int s = decimal.scale() ;

    View Full Code Here
       1: 
       2: import java.math.BigDecimal;
       3: 
       4:         ...
       5: 
       6:    protected static BigDecimal acos(final BigDecimal bd)
       7:          throws OperationException {
       8:         ...
       9:    protected static BigDecimal ln(final BigDecimal bd) {
      10:       double logBD = Math.log(bd.unscaledValue().doubleValue()) - bd.scale()
      11:             * Math.log(BASE_TEN);

    View Full Code Here
       1: 
       2: import java.math.BigDecimal;
       3: import java.math.BigInteger;
       4:         ...
       5:         ByteArrayOutputStream b = new ByteArrayOutputStream();
       6:         BigDecimal d = new BigDecimal("12234.54689");
       7: 
       8:         ...
       9: 
      10:         BigDecimal r = read(bin, d.scale());
    

    View Full Code Here
       1: import java.io.IOException;
       2: import java.math.BigDecimal;
       3: import java.math.BigInteger;
       4:         ...
       5:     public String getPreferredValueClassName() {
       6:         return "java.math.BigDecimal";
       7:     }
       8:         ...
       9:     public String toString() {
      10:         return "BigDecimal";
      11:     }
      12:         ...
      13:             try {
      14:                 if(toreturn.scale() != 2) {

    View Full Code Here

    scaleByPowerOfTen

    public BigDecimal scaleByPowerOfTen(int n)
    Returns a BigDecimal whose numerical value is equal to (this * 10n). The scale of the result is (this.scale() - n).
    Throws:
    ArithmeticException - if the scale would be outside the range of a 32-bit integer.
    Since:
    1.5

    setScale

    public BigDecimal setScale(int newScale)
    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 changing its value.

    This method returns the same result as the two-argument versions 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:
    newScale - scale of the BigDecimal value to be returned.
    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.
    Throws:
    ArithmeticException - if the specified scaling operation would require rounding.
    Usages and Demos :

    View More Examples of setScale(int newScale)
       1: 
       2:     public BigDecimal round (BigDecimal qty, boolean stdPrecision)
       3:     {
       4:         ...
       5:         if (qty.scale() > precision)
       6:             return qty.setScale(getStdPrecision(), BigDecimal.ROUND_HALF_UP);
       7:         return qty;
       8: 
    

    View Full Code Here
       1:             Number number = m_format.parse(value);
       2:             BigDecimal bd = new BigDecimal(value);
       3:             if (m_displayType == DisplayType.Integer)
       4:         ...
       5:                 return bd;
       6:             return bd.setScale(m_format.getMaximumFractionDigits(), BigDecimal.ROUND_HALF_UP);
       7:         }
       8:         ...
       9:         }
      10:         if (value instanceof BigDecimal)
      11:             value = ((BigDecimal)value).add(Env.ONE);

    View Full Code Here
       1: 
       2: import java.math.BigDecimal;
       3: import java.net.URL;
       4:         ...
       5: 
       6:     public final BigDecimal getBigDecimal(int parameterIndex, int scale)
       7:             throws SQLException {
       8:         ...
       9:             resContext.set(parameterIndex);
      10:             BigDecimal bd = resTypes[parameterIndex].getBigDecimal(resData,
      11:                     resContext);
      12:         ...
      13:             return null == bd ? null : bd.setScale(scale);

    View Full Code Here
       1: 
       2: import java.math.BigDecimal;
       3: 
       4:         ...
       5:         }
       6:         public BigDecimal getBigDecimal(Object row, ConversionContext ctx)
       7:                 throws SQLException {
       8:         ...
       9:                 int dscale = n_sign_dscale & PGConstants.NUMERIC_DSCALE_MASK;
      10:                 BigDecimal bd;
      11:                 if (6 == data.length) {
      12:         ...
      13:                 }
      14:                 return bd.setScale(dscale);

    View Full Code Here
       1: import java.io.Reader;
       2: import java.math.BigDecimal;
       3: import java.net.URL;
       4:         ...
       5: 
       6:     public BigDecimal getBigDecimal (int columnIndex) throws SQLException{
       7:         Object cell =  get_cell_from_index(columnIndex);
       8:         ...
       9:         return (BigDecimal)cell;
      10:     }
      11:         ...
      12:         BigDecimal bd = getBigDecimal(columnIndex);
      13:         bd.setScale(scale);

    View Full Code Here

    setScale

    public 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. 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.

    The new setScale(int,RoundingMode) method should be used in preference to this legacy method.

    Parameters:
    newScale - scale of the BigDecimal value to be returned.
    roundingMode - The rounding mode to apply.
    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.
    Throws:
    ArithmeticException - if roundingMode==ROUND_UNNECESSARY and the specified scaling operation would require rounding.
    IllegalArgumentException - if roundingMode does not represent a valid rounding mode.
    Usages and Demos :

    View More Examples of setScale(int newScale,int roundingMode)
       1: 
       2: import java.math.BigDecimal;
       3: 
       4:         ...
       5: 
       6:     protected Object performCalculation(BigDecimal value) {
       7:         ...
       8:         return value.setScale(0, BigDecimal.ROUND_FLOOR);
       9:     }

    View Full Code Here
       1: 
       2: import java.math.BigDecimal;
       3: 
       4:         ...
       5: 
       6:     protected Object performCalculation(BigDecimal value) {
       7:         ...
       8:         return value.setScale(0, BigDecimal.ROUND_CEILING);
       9:     }

    View Full Code Here
       1: 
       2: import java.math.BigDecimal;
       3: import java.math.BigInteger;
       4:         ...
       5:     throws HibernateException, SQLException {
       6:         BigDecimal bigDecimal = rs.getBigDecimal(name);
       7:         return bigDecimal==null ? null : 
       8:         ...
       9:             bigDecimal.setScale(0, BigDecimal.ROUND_UNNECESSARY).unscaledValue();
      10:     }

    View Full Code Here
       1: 
       2: import java.math.BigDecimal;
       3: 
       4:         ...
       5: 
       6:     protected Object performCalculation(BigDecimal value1, BigDecimal value2) {
       7:         int scale = value2.intValue();
       8:         ...
       9:         if (value1.scale() > scale)
      10:             return value1.setScale(scale, BigDecimal.ROUND_HALF_DOWN);
      11:         else

    View Full Code Here
       1: import java.io.Serializable;
       2: import java.math.BigDecimal;
       3: 
       4:         ...
       5: 
       6:     private BigDecimal amount;
       7: 
       8:         ...
       9:         if (amount != null)
      10:             this.amount = init(new BigDecimal(amount));
      11:         else
      12:         ...
      13:         if (amount != null)
      14:             return amount.setScale(2, BigDecimal.ROUND_HALF_UP);

    View Full Code Here

    setScale

    public 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. 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.
    Parameters:
    newScale - scale of the BigDecimal value to be returned.
    roundingMode - The rounding mode to apply.
    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.
    Throws:
    ArithmeticException - if roundingMode==UNNECESSARY and the specified scaling operation would require rounding.
    Since:
    1.5
    See Also:
    RoundingMode
    Usages and Demos :

    View More Examples of setScale(int newScale,RoundingMode roundingMode)
       1: 
       2: import java.math.BigDecimal;
       3: 
       4:         ...
       5: 
       6:     protected Object performCalculation(BigDecimal value) {
       7:         ...
       8:         return value.setScale(0, BigDecimal.ROUND_FLOOR);
       9:     }

    View Full Code Here
       1: 
       2: import java.math.BigDecimal;
       3: 
       4:         ...
       5: 
       6:     protected Object performCalculation(BigDecimal value) {
       7:         ...
       8:         return value.setScale(0, BigDecimal.ROUND_CEILING);
       9:     }

    View Full Code Here
       1: 
       2: import java.math.BigDecimal;
       3: import java.math.BigInteger;
       4:         ...
       5:     throws HibernateException, SQLException {
       6:         BigDecimal bigDecimal = rs.getBigDecimal(name);
       7:         return bigDecimal==null ? null : 
       8:         ...
       9:             bigDecimal.setScale(0, BigDecimal.ROUND_UNNECESSARY).unscaledValue();
      10:     }

    View Full Code Here
       1: 
       2: import java.math.BigDecimal;
       3: 
       4:         ...
       5: 
       6:     protected Object performCalculation(BigDecimal value1, BigDecimal value2) {
       7:         int scale = value2.intValue();
       8:         ...
       9:         if (value1.scale() > scale)
      10:             return value1.setScale(scale, BigDecimal.ROUND_HALF_DOWN);
      11:         else

    View Full Code Here
       1: import java.io.Serializable;
       2: import java.math.BigDecimal;
       3: 
       4:         ...
       5: 
       6:     private BigDecimal amount;
       7: 
       8:         ...
       9:         if (amount != null)
      10:             this.amount = init(new BigDecimal(amount));
      11:         else
      12:         ...
      13:         if (amount != null)
      14:             return amount.setScale(2, BigDecimal.ROUND_HALF_UP);

    View Full Code Here

    shortValueExact

    public short shortValueExact()
    Converts this BigDecimal to a short, checking for lost information. If this BigDecimal has a nonzero fractional part or is out of the possible range for a short result then an ArithmeticException is thrown.
    Returns:
    this BigDecimal converted to a short.
    Throws:
    ArithmeticException - if this has a nonzero fractional part, or will not fit in a short.
    Since:
    1.5

    signum

    public int signum()
    Returns the signum function of this BigDecimal.
    Returns:
    -1, 0, or 1 as the value of this BigDecimal is negative, zero, or positive.
    Usages and Demos :

    View More Examples of signum()
       1: import java.io.ObjectInputStream;
       2: import java.math.BigDecimal;
       3: import java.math.BigInteger;
       4:         ...
       5:     protected BigInteger minute;
       6:     protected BigDecimal second;
       7: 
       8:         ...
       9:         BigInteger year, BigInteger month, BigInteger day,
      10:         BigInteger hour, BigInteger minute, BigDecimal second ) {
      11:         this.signum  = signum;
      12:         ...
      13:     public static BigTimeDurationValueType fromMinutes( BigInteger minutes )
      14:     { return new BigTimeDurationValueType(minutes.signum(),null,null,null,null,minutes.abs(),null); }

    View Full Code Here
       1: 
       2: import java.math.BigDecimal;
       3: import java.math.BigInteger;
       4:         ...
       5: 
       6:     private BigDecimal value;
       7: 
       8:         ...
       9: 
      10:     public DecimalValue(BigDecimal value) {
      11:         this.value = value;
      12:         ...
      13:     public boolean effectiveBooleanValue(XPathContext context) {
      14:         return value.signum() != 0;

    View Full Code Here
       1: 
       2: import java.math.BigDecimal;
       3: import java.math.BigInteger;
       4:         ...
       5:     
       6:     BigDecimal value;
       7: 
       8:         ...
       9:     public DecimalValue(BigDecimal decimal) {
      10:         this.value = decimal;
      11:         ...
      12:         } else {
      13:             boolean negative = value.signum() < 0;

    View Full Code Here
       1: import java.awt.Toolkit;
       2: import java.math.BigDecimal;
       3: import java.math.BigInteger;
       4:         ...
       5:     
       6:     private BigDecimal myBigDecimal = null;
       7:     
       8:         ...
       9:         String text = numFormatter.format( doubleIn );                
      10:         myBigDecimal = new BigDecimal( text );
      11:         
      12:         ...
      13:             
      14:             if ( magnitude.signum() == 0 ) magnitude = new BigDecimal( "1" );

    View Full Code Here
       1:             long ms = System.currentTimeMillis() - m_audit.getCreated().getTime();
       2:             m_audit.setElapsedTimeMS(new BigDecimal(ms));
       3:         }
       4:         ...
       5:     public int getApprovalUser (int AD_User_ID, 
       6:             int C_Currency_ID, BigDecimal amount, 
       7:             int AD_Org_ID, boolean ownDocument)
       8:         ...
       9:         if (amount == null 
      10:             || amount.signum() == 0)
      11:             return AD_User_ID;
      12:         ...
      13:                     continue;
      14:                 BigDecimal roleAmt = role.getAmtApproval();

    View Full Code Here

    stripTrailingZeros

    public BigDecimal stripTrailingZeros()
    Returns a BigDecimal which is numerically equal to this one but with any trailing zeros removed from the representation. For example, stripping the trailing zeros from the BigDecimal value 600.0, which has [BigInteger, scale] components equals to [6000, 1], yields 6E2 with [BigInteger, scale] components equals to [6, -2]
    Returns:
    a numerically equal BigDecimal with any trailing zeros removed.

    subtract

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

    View More Examples of subtract(BigDecimal subtrahend)
       1: 
       2: import java.math.BigDecimal;
       3: 
       4:         ...
       5: 
       6:     protected Object performCalculation(BigDecimal value1, BigDecimal value2) {
       7:         ...
       8:         return value1.subtract(value2);
       9:     }

    View Full Code Here
       1: 
       2: import java.math.BigDecimal;
       3: 
       4:         ...
       5: 
       6:     protected Object performCalculation(BigDecimal value1, BigDecimal value2) {
       7:         value1 = value1.abs();
       8:         ...
       9:         quotient = quotient.setScale(0, BigDecimal.ROUND_DOWN);
      10:         return value1.subtract(quotient.multiply(value2));
      11:     }

    View Full Code Here
       1: 
       2: import java.math.BigDecimal;
       3: 
       4:         ...
       5: {
       6:   private BigDecimal income;
       7:         ...
       8:   private BigDecimal expense;
       9: 
      10:         ...
      11:     {
      12:       return income.subtract(expense);

    View Full Code Here
       1:             return "";
       2:         BigDecimal OpenAmt = (BigDecimal)mTab.getValue("OpenAmt");
       3:         ...
       4:         BigDecimal PayAmt = (BigDecimal)mTab.getValue("PayAmt");
       5:         BigDecimal DiscountAmt = (BigDecimal)mTab.getValue("DiscountAmt");
       6:         ...
       7:         setCalloutActive(true);
       8:         BigDecimal DifferenceAmt = OpenAmt.subtract(PayAmt).subtract(DiscountAmt);
       9:         log.fine(" - OpenAmt=" + OpenAmt + " - PayAmt=" + PayAmt
      10:         ...
      11:         mTab.setValue("OpenAmt", OpenAmt);
      12:         mTab.setValue("PayAmt", OpenAmt.subtract(DiscountAmt));

    View Full Code Here
       1:                 mTab.setValue("C_Currency_ID", new Integer(rs.getInt(2)));
       2:                 BigDecimal PayAmt = rs.getBigDecimal(3);
       3:         ...
       4:                 BigDecimal DiscountAmt = rs.getBigDecimal(5);
       5:                 boolean isSOTrx = "Y".equals(rs.getString(4));
       6:         ...
       7:                 }
       8:                 mTab.setValue("Amount", PayAmt.subtract(DiscountAmt));
       9:                 mTab.setValue("DiscountAmt", DiscountAmt);
      10:         ...
      11:             return "";
      12:         BigDecimal InvTotalAmt = new BigDecimal(total);

    View Full Code Here

    subtract

    public BigDecimal subtract(BigDecimal subtrahend,
                               MathContext mc)
    Returns a BigDecimal whose value is (this - subtrahend), with rounding according to the context settings. If subtrahend is zero then this, rounded if necessary, is used as the result. If this is zero then the result is subtrahend.negate(mc).
    Parameters:
    subtrahend - value to be subtracted from this BigDecimal.
    mc - the context to use.
    Returns:
    this - subtrahend, rounded as necessary.
    Throws:
    ArithmeticException - if the result is inexact but the rounding mode is UNNECESSARY.
    Since:
    1.5
    Usages and Demos :

    View More Examples of subtract(BigDecimal subtrahend,MathContext mc)
       1: 
       2: import java.math.BigDecimal;
       3: import java.math.BigInteger;
       4:         ...
       5:     
       6:     BigDecimal value;
       7: 
       8:         ...
       9:     public DecimalValue(BigDecimal decimal) {
      10:         this.value = decimal;
      11:         ...
      12:             BigDecimal remainder =
      13:                 value.subtract(quotient.setScale(0, BigDecimal.ROUND_DOWN).multiply(((DecimalValue) other).value));

    View Full Code Here

    toBigInteger

    public BigInteger toBigInteger()
    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.

    To have an exception thrown if the conversion is inexact (in other words if a nonzero fractional part is discarded), use the toBigIntegerExact() method.

    Returns:
    this BigDecimal converted to a BigInteger.
    Usages and Demos :

    View More Examples of toBigInteger()
       1: 
       2: import java.math.BigDecimal;
       3: import java.math.BigInteger;
       4:         ...
       5: 
       6:      public BigDecimal toBigDecimal(BigInteger bInteger) {
       7:         ...
       8:           return (bInteger == null) ? null : new BigDecimal(bInteger);
       9:      }
      10:         ...
      11:      public BigInteger toBigInteger(BigDecimal bDecimal) {
      12:           return (bDecimal == null) ? null : bDecimal.toBigInteger();

    View Full Code Here
       1: import java.io.IOException;
       2: import java.math.BigDecimal;
       3: import java.math.BigInteger;
       4:         ...
       5:     out.print(" == null || " + rs + ".wasNull() ? null : ");
       6:     out.print(rs + ".getBigDecimal(" + indexVar + " + " + index + ").toBigInteger()");
       7: 
       8:         ...
       9:     out.println("else");
      10:     out.println("  " + pstmt + ".setBigDecimal(" + index + "++, new java.math.BigDecimal(" + value + "));");
      11:   }
      12:         ...
      13:     else
      14:       pstmt.setBigDecimal(index, new BigDecimal((BigInteger) value));

    View Full Code Here
       1: import java.math.BigInteger;
       2: import java.math.BigDecimal;
       3: 
       4:         ...
       5: 
       6:     public BigDecimal bigDecimalValue() { check_dated(); return BigDecimal.valueOf(_value); }
       7:     public BigInteger bigIntegerValue() { check_dated(); return BigInteger.valueOf(_value); }
       8:         ...
       9: 
      10:     protected void set_BigDecimal(BigDecimal v) { set_BigInteger(v.toBigInteger()); }
      11:     protected void set_BigInteger(BigInteger v)

    View Full Code Here
       1: 
       2: import java.math.BigDecimal;
       3: import java.math.BigInteger;
       4:         ...
       5:     }
       6:     public BigDecimal bigDecimalValue() { check_dated(); return _value == null ? null : new BigDecimal(_value); }
       7:     public BigInteger bigIntegerValue() { check_dated(); return _value; }
       8:         ...
       9: 
      10:     protected void set_BigDecimal(BigDecimal v) { _value = v.toBigInteger(); }
      11:     protected void set_BigInteger(BigInteger v) { _value = v; }

    View Full Code Here
       1: 
       2: import java.math.BigDecimal;
       3: import java.math.BigInteger;
       4:         ...
       5:     }
       6:     public BigDecimal bigDecimalValue() { check_dated(); return new BigDecimal(_value); }
       7:     public BigInteger bigIntegerValue() { check_dated(); return BigInteger.valueOf(_value); }
       8:         ...
       9: 
      10:     protected void set_BigDecimal(BigDecimal v) { set_BigInteger(v.toBigInteger()); }
      11:     protected void set_BigInteger(BigInteger v)

    View Full Code Here

    toBigIntegerExact

    public BigInteger toBigIntegerExact()
    Converts this BigDecimal to a BigInteger, checking for lost information. An exception is thrown if this BigDecimal has a nonzero fractional part.
    Returns:
    this BigDecimal converted to a BigInteger.
    Throws:
    ArithmeticException - if this has a nonzero fractional part.
    Since:
    1.5

    toEngineeringString

    public String toEngineeringString()
    Returns a string representation of this BigDecimal, using engineering notation if an exponent is needed.

    Returns a string that represents the BigDecimal as described in the toString() method, except that if exponential notation is used, the power of ten is adjusted to be a multiple of three (engineering notation) such that the integer part of nonzero values will be in the range 1 through 999. If exponential notation is used for zero values, a decimal point and one or two fractional zero digits are used so that the scale of the zero value is preserved. Note that unlike the output of toString(), the output of this method is not guaranteed to recover the same [integer, scale] pair of this BigDecimal if the output string is converting back to a BigDecimal using the string constructor. The result of this method meets the weaker constraint of always producing a numerically equal result from applying the string constructor to the method's output.

    Returns:
    string representation of this BigDecimal, using engineering notation if an exponent is needed.
    Since:
    1.5
    Usages and Demos :

    View More Examples of toEngineeringString()
       1: import org.apache.tools.ant.Task;
       2: import java.math.BigDecimal;
       3: 
       4:         ...
       5: public class Bignum extends Task {
       6:     private BigDecimal value;
       7: 
       8:         ...
       9:     public void setValue(BigDecimal value) {
      10:         this.value = value;
      11:         ...
      12:     public void execute() {
      13:         log(value.toEngineeringString());

    View Full Code Here

    toPlainString

    public String toPlainString()
    Returns a string representation of this BigDecimal without an exponent field. For values with a positive scale, the number of digits to the right of the decimal point is used to indicate scale. For values with a zero or negative scale, the resulting string is generated as if the value were converted to a numerically equal value with zero scale and as if all the trailing zeros of the zero scale value were present in the result. The entire string is prefixed by a minus sign character '-' ('\u002D') if the unscaled value is less than zero. No sign character is prefixed if the unscaled value is zero or positive. Note that if the result of this method is passed to the string constructor, only the numerical value of this BigDecimal will necessarily be recovered; the representation of the new BigDecimal may have a different scale. In particular, if this BigDecimal has a positive scale, the string resulting from this method will have a scale of zero when processed by the string constructor. (This method behaves analogously to the toString method in 1.4 and earlier releases.)
    Returns:
    a string representation of this BigDecimal without an exponent field.
    Since:
    1.5
    Usages and Demos :

    View More Examples of toPlainString()
       1: 
       2: import java.math.BigDecimal;
       3: import java.text.SimpleDateFormat;
       4:         ...
       5:     
       6:     static public String stringForm(BigDecimal decimal)
       7:     { 
       8:         return decimal.toString() ;
       9:     }

    View Full Code Here

    toString

    public String toString()
    Returns the string representation of this BigDecimal, using scientific notation if an exponent is needed.

    A standard canonical string form of the BigDecimal is created as though by the following steps: first, the absolute value of the unscaled value of the BigDecimal is converted to a string in base ten using the characters '0' through '9' with no leading zeros (except if its value is zero, in which case a single '0' character is used).

    Next, an adjusted exponent is calculated; this is the negated scale, plus the number of characters in the converted unscaled value, less one. That is, -scale+(ulength-1), where ulength is the length of the absolute value of the unscaled value in decimal digits (its precision).

    If the scale is greater than or equal to zero and the adjusted exponent is greater than or equal to -6, the number will be converted to a character form without using exponential notation. In this case, if the scale is zero then no decimal point is added and if the scale is positive a decimal point will be inserted with the scale specifying the number of characters to the right of the decimal point. '0' characters are added to the left of the converted unscaled value as necessary. If no character precedes the decimal point after this insertion then a conventional '0' character is prefixed.

    Otherwise (that is, if the scale is negative, or the adjusted exponent is less than -6), the number will be converted to a character form using exponential notation. In this case, if the converted BigInteger has more than one digit a decimal point is inserted after the first digit. An exponent in character form is then suffixed to the converted unscaled value (perhaps with inserted decimal point); this comprises the letter 'E' followed immediately by the adjusted exponent converted to a character form. The latter is in base ten, using the characters '0' through '9' with no leading zeros, and is always prefixed by a sign character '-' ('\u002D') if the adjusted exponent is negative, '+' ('\u002B') otherwise).

    Finally, the entire string is prefixed by a minus sign character '-' ('\u002D') if the unscaled value is less than zero. No sign character is prefixed if the unscaled value is zero or positive.

    Examples:

    For each representation [unscaled value, scale] on the left, the resulting string is shown on the right.

     [123,0]      "123"
     [-123,0]     "-123"
     [123,-1]     "1.23E+3"
     [123,-3]     "1.23E+5"
     [123,1]      "12.3"
     [123,5]      "0.00123"
     [123,10]     "1.23E-8"
     [-123,12]    "-1.23E-10"
     
    Notes:
    1. There is a one-to-one mapping between the distinguishable BigDecimal values and the result of this conversion. That is, every distinguishable BigDecimal value (unscaled value and scale) has a unique string representation as a result of using toString. If that string representation is converted back to a BigDecimal using the BigDecimal(String) constructor, then the original value will be recovered.
    2. The string produced for a given number is always the same; it is not affected by locale. This means that it can be used as a canonical string representation for exchanging decimal data, or as a key for a Hashtable, etc. Locale-sensitive number formatting and parsing is handled by the NumberFormat class and its subclasses.
    3. The toEngineeringString() method may be used for presenting numbers with exponents in engineering notation, and the setScale method may be used for rounding a BigDecimal so it has a known number of digits after the decimal point.
    4. The digit-to-character mapping provided by Character.forDigit is used.
    Overrides:
    toString in interface Object
    Returns:
    string representation of this BigDecimal.
    Usages and Demos :

    View More Examples of toString()
       1: import java.io.Serializable;
       2: import java.math.BigDecimal;
       3: 
       4:         ...
       5:     private static Object NULL_UNIT_OF_MEASURE = new Object();
       6:     public static Quantity ZERO = new Quantity(new BigDecimal(0), null);
       7: 
       8:         ...
       9:     protected BigDecimal magnitude;
      10:     protected Object unitOfMeasure;
      11:         ...
      12:     public Quantity(Integer magnitude, Object unitOfMeasure) {
      13:         this(new BigDecimal(magnitude.toString()), unitOfMeasure);

    View Full Code Here
       1: import org.geotools.xml.SimpleBinding;
       2: import java.math.BigDecimal;
       3: import javax.xml.namespace.QName;
       4:         ...
       5:     public Class getType() {
       6:         return BigDecimal.class;
       7:     }
       8:         ...
       9:         throws Exception {
      10:         return new BigDecimal((String) value);
      11:     }
      12:         ...
      13: 
      14:         return decimal.toString();

    View Full Code Here
       1: 
       2: import java.math.BigDecimal;
       3: 
       4:         ...
       5:         super();
       6:         setSourceClass(BigDecimal.class);
       7:         setTargetClass(String.class);
       8:         ...
       9:                         throws ConvertException {
      10:         BigDecimal bigDecimal = (BigDecimal) source;
      11:         ...
      12:         return bigDecimal.toString();

    View Full Code Here
       1: 
       2: import java.math.BigDecimal;
       3: 
       4:         ...
       5: 
       6:     protected BigDecimal _content;
       7: 
       8:         ...
       9:     {
      10:         BigDecimal givenValue = (BigDecimal)val.getContent();
      11: 
      12:         ...
      13: 
      14:         out.write("<" + thePrefix + ":decimal>" + _content.toString() + "</" + thePrefix + ":decimal>");

    View Full Code Here
       1: 
       2: import java.math.BigDecimal;
       3: import java.text.SimpleDateFormat;
       4:         ...
       5:     
       6:     static public String stringForm(BigDecimal decimal)
       7:     { 
       8:         ...
       9:         return decimal.toString() ;
      10:     }

    View Full Code Here

    ulp

    public BigDecimal ulp()
    Returns the size of an ulp, a unit in the last place, of this BigDecimal. An ulp of a nonzero BigDecimal value is the positive distance between this value and the BigDecimal value next larger in magnitude with the same number of digits. An ulp of a zero value is numerically equal to 1 with the scale of this. The result is stored with the same scale as this so the result for zero and nonzero values is equal to [1, this.scale()].
    Returns:
    the size of an ulp of this
    Since:
    1.5

    unscaledValue

    public BigInteger unscaledValue()
    Returns a BigInteger whose value is the unscaled value of this BigDecimal. (Computes (this * 10this.scale()).)
    Returns:
    the unscaled value of this BigDecimal.
    Since:
    1.2
    Usages and Demos :

    View More Examples of unscaledValue()
       1: 
       2: import java.math.BigDecimal;
       3: 
       4:         ...
       5: 
       6:    protected static BigDecimal acos(final BigDecimal bd)
       7:          throws OperationException {
       8:         ...
       9:    protected static BigDecimal ln(final BigDecimal bd) {
      10:       double logBD = Math.log(bd.unscaledValue().doubleValue()) - bd.scale()
      11:             * Math.log(BASE_TEN);

    View Full Code Here
       1: import java.sql.SQLException;
       2: import java.math.BigDecimal;
       3: import java.math.BigInteger;
       4:         ...
       5: 
       6:         BigDecimal value = getBigDecimal();
       7:         
       8:         ...
       9:         
      10:         BigDecimal value = getBigDecimal();
      11:         
      12:         ...
      13: 
      14:             if (value.unscaledValue().compareTo(MAX_SHORT) > 0 ||

    View Full Code Here
       1: 
       2: import java.math.BigDecimal;
       3: 
       4:         ...
       5: 
       6:         BigDecimal v = null;
       7:         try {
       8:         ...
       9:             v = new BigDecimal(s);
      10:         }
      11:         ...
      12:         {
      13:             String temp = v.unscaledValue().toString();

    View Full Code Here
       1: 
       2: import java.math.BigDecimal;
       3: import java.math.BigInteger;
       4:         ...
       5:     private int _s;
       6:     private BigDecimal _fs;
       7:     private int _tzsign;
       8:         ...
       9:             int second,
      10:             BigDecimal fraction)
      11:     {
      12:         ...
      13:             return 0;
      14:         return _fs.setScale(3, BigDecimal.ROUND_HALF_UP).unscaledValue().intValue();

    View Full Code Here

    valueOf

    public 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.

    Note: This is generally the preferred way to convert a double (or float) into a BigDecimal, as the value returned is equal to that resulting from constructing a BigDecimal from the result of using Double.toString(double).

    Parameters:
    val - double to convert to a BigDecimal.
    Returns:
    a BigDecimal whose value is equal to or approximately equal to the value of val.
    Throws:
    NumberFormatException - if val is infinite or NaN.
    Since:
    1.5
    Usages and Demos :

    View More Examples of valueOf(double val)
       1: import java.io.Serializable;
       2: import java.math.BigDecimal;
       3: import java.math.BigInteger;
       4:         ...
       5:             try {
       6:                 return new BigDecimal( (String) value ).compareTo( BigDecimal.valueOf(min) ) >= 0;
       7:             }
       8:         ...
       9:         else if ( value instanceof BigInteger ) {
      10:             return ( (BigInteger) value ).compareTo( BigInteger.valueOf( min ) ) >= 0;
      11:         }
      12:         ...
      13:         else if ( value instanceof BigDecimal ) {

    View Full Code Here
       1: import java.io.Serializable;
       2: import java.math.BigDecimal;
       3: import java.math.BigInteger;
       4:         ...
       5:             try {
       6:                 return new BigDecimal( (String) value ).compareTo( BigDecimal.valueOf( max ) ) <= 0;
       7:             }
       8:         ...
       9:         else if ( value instanceof BigInteger ) {
      10:             return ( (BigInteger) value ).compareTo( BigInteger.valueOf( max ) ) <= 0;
      11:         }
      12:         ...
      13:         else if ( value instanceof BigDecimal ) {

    View Full Code Here
       1: import java.io.Serializable;
       2: import java.math.BigDecimal;
       3: 
       4:         ...
       5:             try {
       6:                 BigDecimal dv = new BigDecimal( (String) value );
       7:         ...
       8:                 return dv.compareTo( BigDecimal.valueOf( min ) ) >= 0 && dv.compareTo( BigDecimal.valueOf( max ) ) <= 0;
       9:             }

    View Full Code Here
       1: 
       2: import java.math.BigDecimal;
       3: import java.sql.SQLException;
       4:         ...
       5:     }
       6:     public BigDecimal getBigDecimal() throws SQLException {
       7:         if (getFieldData()==null) return BIGDECIMAL_NULL_VALUE;
       8:         ...
       9: 
      10:         return BigDecimal.valueOf(field.decodeShort(getFieldData()));
      11:     }
      12:         ...
      13: 
      14:         return String.valueOf(field.decodeShort(getFieldData()));

    View Full Code Here
       1: import java.sql.SQLException;
       2: import java.math.BigDecimal;
       3: 
       4:         ...
       5:     }
       6:     public BigDecimal getBigDecimal() throws SQLException {
       7:         if (getFieldData()==null) return BIGDECIMAL_NULL_VALUE;
       8:         ...
       9: 
      10:         return BigDecimal.valueOf(field.decodeInt(getFieldData()));
      11:     }
      12:         ...
      13: 
      14:         return String.valueOf(field.decodeInt(getFieldData()));

    View Full Code Here

    valueOf

    public static BigDecimal valueOf(long val)
    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 BigDecimal values.
    Parameters:
    val - value of the BigDecimal.
    Returns:
    a BigDecimal whose value is val.
    Usages and Demos :

    View More Examples of valueOf(long val)
       1: import java.io.Serializable;
       2: import java.math.BigDecimal;
       3: import java.math.BigInteger;
       4:         ...
       5:             try {
       6:                 return new BigDecimal( (String) value ).compareTo( BigDecimal.valueOf(min) ) >= 0;
       7:             }
       8:         ...
       9:         else if ( value instanceof BigInteger ) {
      10:             return ( (BigInteger) value ).compareTo( BigInteger.valueOf( min ) ) >= 0;
      11:         }
      12:         ...
      13:         else if ( value instanceof BigDecimal ) {

    View Full Code Here
       1: import java.io.Serializable;
       2: import java.math.BigDecimal;
       3: import java.math.BigInteger;
       4:         ...
       5:             try {
       6:                 return new BigDecimal( (String) value ).compareTo( BigDecimal.valueOf( max ) ) <= 0;
       7:             }
       8:         ...
       9:         else if ( value instanceof BigInteger ) {
      10:             return ( (BigInteger) value ).compareTo( BigInteger.valueOf( max ) ) <= 0;
      11:         }
      12:         ...
      13:         else if ( value instanceof BigDecimal ) {

    View Full Code Here
       1: import java.io.Serializable;
       2: import java.math.BigDecimal;
       3: 
       4:         ...
       5:             try {
       6:                 BigDecimal dv = new BigDecimal( (String) value );
       7:         ...
       8:                 return dv.compareTo( BigDecimal.valueOf( min ) ) >= 0 && dv.compareTo( BigDecimal.valueOf( max ) ) <= 0;
       9:             }

    View Full Code Here
       1: 
       2: import java.math.BigDecimal;
       3: import java.sql.SQLException;
       4:         ...
       5:     }
       6:     public BigDecimal getBigDecimal() throws SQLException {
       7:         if (getFieldData()==null) return BIGDECIMAL_NULL_VALUE;
       8:         ...
       9: 
      10:         return BigDecimal.valueOf(field.decodeShort(getFieldData()));
      11:     }
      12:         ...
      13: 
      14:         return String.valueOf(field.decodeShort(getFieldData()));

    View Full Code Here
       1: import java.sql.SQLException;
       2: import java.math.BigDecimal;
       3: 
       4:         ...
       5:     }
       6:     public BigDecimal getBigDecimal() throws SQLException {
       7:         if (getFieldData()==null) return BIGDECIMAL_NULL_VALUE;
       8:         ...
       9: 
      10:         return BigDecimal.valueOf(field.decodeInt(getFieldData()));
      11:     }
      12:         ...
      13: 
      14:         return String.valueOf(field.decodeInt(getFieldData()));

    View Full Code Here

    valueOf

    public static BigDecimal valueOf(long unscaledVal,
                                     int scale)
    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 BigDecimal values..
    Parameters:
    unscaledVal - unscaled value of the BigDecimal.
    scale - scale of the BigDecimal.
    Returns:
    a BigDecimal whose value is (unscaledVal × 10-scale).
    Usages and Demos :

    View More Examples of valueOf(long unscaledVal,int scale)
       1: 
       2: import java.math.BigDecimal;
       3: import java.math.BigInteger;
       4:         ...
       5: 
       6:     public static final BigDecimal ZERO = BigDecimal.valueOf(0);
       7:     public static final BigDecimal ONE = BigDecimal.valueOf(1);
       8:         ...
       9:     public static BigDecimal valueOf(long val) {
      10:         return BigDecimal.valueOf(val, 0);
      11:     }

    View Full Code Here
       1: 
       2: import java.math.BigDecimal;
       3: import java.math.BigInteger;
       4:         ...
       5:     public void testConstants() throws Exception {
       6:         assertEquals(0, BigDecimal.ZERO.intValue());
       7:         ...
       8:         assertEquals(1, BigDecimal.ONE.intValue());
       9:         assertEquals(10, BigDecimal.TEN.intValue());
      10:         ...
      11:     public void testDivideToIntegralValue_zeroDividend() throws Exception {
      12:         BigDecimal dividend = BigDecimal.valueOf(0, 10);

    View Full Code Here
       1: import java.sql.SQLException;
       2: import java.math.BigDecimal;
       3: import java.math.BigInteger;
       4:         ...
       5: 
       6:         BigDecimal value = getBigDecimal();
       7:         
       8:         ...
       9:         
      10:         BigDecimal value = getBigDecimal();
      11:         
      12:         ...
      13: 
      14:         return BigDecimal.valueOf(longValue, -field.sqlscale);

    View Full Code Here
       1: import java.io.Serializable;
       2: import java.math.BigDecimal;
       3: import java.text.NumberFormat;
       4:         ...
       5: 
       6:     public BigDecimal getDecimalAmount() {
       7:         ...
       8:         return BigDecimal.valueOf(amount, currency.getDefaultFractionDigits());
       9:     }
      10:         ...
      11:     public Money multiply(double multiplier) {
      12:         return multiply(new BigDecimal(multiplier));

    View Full Code Here
       1: import java.io.Serializable;
       2: import java.math.BigDecimal;
       3: import java.math.BigInteger;
       4:         ...
       5:     
       6:     private BigDecimal fractionalSecond = null;
       7: 
       8:         ...
       9:         int second,
      10:         BigDecimal fractionalSecond,
      11:         int timezone) {
      12:         ...
      13:         if (millisecond != DatatypeConstants.FIELD_UNDEFINED) {
      14:             realMilliseconds = BigDecimal.valueOf(millisecond, 3);

    View Full Code Here