Java Utililty Methods BigDecimal to

List of utility methods to do BigDecimal to

Description

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

Method

StringdecimalToString(BigDecimal value)
Creates a canonical string representation of the supplied BigDecimal value, whereby all string representations are lexicographically sortable.
StringBuilder sb = new StringBuilder();
boolean negate = false;
switch (value.signum()) {
case -1:
    sb.append('-');
    negate = true;
    break;
case 1:
...
StringtoBeforeDecimalPointString(BigDecimal bigDecimal)
to Before Decimal Point String
String value = bigDecimal.toPlainString();
if (!value.contains(".")) {
    return bigDecimal.toPlainString();
String[] strings = value.split("\\.");
return strings[0];
DoubletoDouble(BigDecimal b, boolean allownull)
to Double
if (allownull && b == null)
    return null;
return b.doubleValue();
doubletoDouble(BigDecimal bigDecimal)
to Double
double result = 0.0;
if (bigDecimal != null) {
    result = bigDecimal.doubleValue();
return result;
DoubletoDouble(final BigDecimal b)
to Double
if (b == null) {
    return null;
String s = DecimalToS(b);
return new Double(s);
doubletoDouble(final BigDecimal b)
Null save convert of a BigDecimal to a double.
if (b != null) {
    return b.doubleValue();
} else {
    return 0d;
LongtoInteger(BigDecimal b)
to Integer
return b == null ? null : b.longValue();
ObjecttoLong(BigDecimal value)
Returns the Long represented by the given value, or null if not an long value.
Object number;
try {
    number = value.scale() == 0 ? Long.valueOf(value.longValueExact()) : null;
} catch (Exception e) {
    number = null;
return number;
LongtoLongObject(@Nullable final BigDecimal value)
to Long Object
return (value == null ? null : Long.valueOf(value.longValue()));
TtoNumber(final BigDecimal bigDecimal, final Class clazz)
to Number
if (bigDecimal == null) {
    return null;
} else if (BigDecimal.class.isAssignableFrom(clazz)) {
    return (T) bigDecimal;
} else if (Byte.class.isAssignableFrom(clazz)) {
    return (T) new Byte(bigDecimal.byteValue());
} else if (Short.class.isAssignableFrom(clazz)) {
    return (T) new Short(bigDecimal.shortValue());
...