Java Utililty Methods BigDecimal from

List of utility methods to do BigDecimal from

Description

The list of methods to do BigDecimal from are organized into topic(s).

Method

BigDecimaltoBigDecimal(final Double d)
Null save convert of a Double to a BigDecimal .
if (d != null) {
    return BigDecimal.valueOf(d);
} else {
    return null;
BigDecimaltoBigDecimal(final Number n)
to Big Decimal
if (n == null || n instanceof BigDecimal)
    return (BigDecimal) n;
if (n instanceof BigInteger)
    return new BigDecimal((BigInteger) n);
return BigDecimal.valueOf(n.doubleValue());
BigDecimaltoBigDecimal(final Number number)
to Big Decimal
if (number instanceof Integer || number instanceof Long) {
    return new BigDecimal(number.longValue());
} else if (number instanceof Float || number instanceof Double) {
    return new BigDecimal(number.doubleValue());
} else {
    throw new RuntimeException(
            "Unexpected data type passed in to toBigDecimal (" + number.getClass() + ")");
BigDecimaltoBigDecimal(final Number number)
To big decimal.
if ((number instanceof Integer) || (number instanceof Long)) {
    return new BigDecimal(number.longValue());
} else if ((number instanceof Float) || (number instanceof Double)) {
    return new BigDecimal(number.doubleValue());
} else {
    throw new NumberFormatException(
            "Unexpected data type passed in to toBigDecimal (" + number.getClass() + ")");
BigDecimaltoBigDecimal(final Number number)
to Big Decimal
if (number == null) {
    return null;
} else if (number instanceof BigDecimal) {
    return (BigDecimal) number;
} else if (number instanceof Byte) {
    return new BigDecimal((Byte) number);
} else if (number instanceof Short) {
    return new BigDecimal((Short) number);
...
BigDecimaltoBigDecimal(final String bigdecimal)
To big decimal.
if (bigdecimal == null) {
    return null;
if (bigdecimal.length() < 1) {
    return null;
try {
    return new BigDecimal(bigdecimal);
...
BigDecimaltoBigDecimal(final String string)
to Big Decimal
if (string == null || string.isEmpty()) {
    return BigDecimal.ZERO;
return new BigDecimal(string);
BigDecimaltoBigDecimal(final String value)
to Big Decimal
return new BigDecimal(value);
BigDecimaltoBigDecimal(Integer num)
to Big Decimal
try {
    return roundBigDecimal(new BigDecimal(num));
} catch (Exception ignored) {
return null;
BigDecimaltoBigDecimal(JsonValue val)
to Big Decimal
if (val instanceof JsonNumber) {
    return ((JsonNumber) val).bigDecimalValue();
return new BigDecimal(toString(val));