Java Code Examples for java.math.BigDecimal#getClass()

The following examples show how to use java.math.BigDecimal#getClass() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: ion-java   File: Decimal.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns a "plain" {@link BigDecimal} instance, never a {@link Decimal}
 * subclass.  As a side effect, this strips any negative-zero information.
 *
 * @param val may be null.
 * @return {@code null} if the given value is {@code null}.
 */
public static BigDecimal bigDecimalValue(BigDecimal val)
{
    if (val == null
        || val.getClass() == BigDecimal.class)
    {
        return val;
    }
    return new BigDecimal(val.unscaledValue(), val.scale());
}
 
Example 2
Source Project: development   File: XMLSerializer.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected Expression instantiate(Object oldInstance, Encoder out) {
    BigDecimal bd = (BigDecimal) oldInstance;
    return new Expression(bd, bd.getClass(), "new",
            new Object[] { bd.toString() });
}
 
Example 3
/**
 * Since BigDecimal is not technically immutable we defensively copy when needed.
 *
 * <p>
 * See Effective Java 2nd ed. page 79 for details.
 * </p>
 *
 * @param val the big decimal to check
 * @return the safe BigDecimal
 */
private static BigDecimal safeInstance(BigDecimal val) {
    if (val.getClass() != BigDecimal.class) {
        return new BigDecimal(val.toPlainString());
    }
    return val;
}
 
Example 4
Source Project: ion-java   File: Decimal.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Efficiently determines whether an arbitary decimal value is a negative
 * zero.  This can only be true when the value is actually a
 * {@link Decimal}.
 *
 * @return {@code true} if and only if the value is a negative zero.
 *
 * @throws NullPointerException if the value is {@code null}.
 */
public static boolean isNegativeZero(BigDecimal val)
{
    return (val.getClass() == NegativeZero.class);
}