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

BigDecimalconvertSecondsToMillis(BigDecimal seconds)
Number of second = # of seconds * 1000 millis
return seconds.multiply(new BigDecimal(1000));
BigDecimalconvertStringToBigDecimal(String strValue)
convert String To Big Decimal
BigDecimal bgValue = new BigDecimal(strValue);
return bgValue;
BigDecimalconvertToBigDecimal(final Object o)
convert To Big Decimal
if (o instanceof Number) {
    return convertToBigDecimal((Number) o);
return null;
BigDecimalconvertToBigDecimal(Object sourceValue)
convert To Big Decimal
if (sourceValue instanceof Number) {
    return new BigDecimal(((Number) sourceValue).toString());
} else if (sourceValue instanceof String) {
    return new BigDecimal((String) sourceValue);
return null;
BigDecimalconvertToBigDecimal(String s)
convert To Big Decimal
if ((s == null) || s.equals("")) {
    return null;
if (s.startsWith("+")) {
    s = s.substring(1);
return new BigDecimal(s);
BigDecimalconvertToBigDecimal(String val)
convert To Big Decimal
BigDecimal returnValue = new BigDecimal(0.00);
if (val == null || val.trim().equals("")) {
    return returnValue;
val = val.replace(",", "");
val = val.replace("$", "");
returnValue = new BigDecimal(val.trim());
return returnValue;
...
BigDecimalconvertToBigDecimal(String value)
convert To Big Decimal
if (value == null || value.trim().isEmpty()) {
    return null;
try {
    return new BigDecimal(value.trim());
} catch (RuntimeException e) {
    throw new Exception("convertToBigDecimal:" + value + " failed:" + e.getMessage(), e);
BigDecimalconvertToBigDecimal(String value)
Convert a string representing a decimal value into a BigDecimal object
BigDecimal result = null;
if (isValid(value)) {
    result = new BigDecimal(value.trim());
return result;
LongconvertToFen(BigDecimal num1)
convert To Fen
if (null == num1) {
    return ZERO.longValue();
BigDecimal temp = multiply(num1, HUNDRED);
return temp.longValue();
intdecimalToBytes(BigDecimal v, byte[] result, final int offset, int length)
decimal To Bytes
int signum = v.signum();
if (signum == 0) {
    result[offset] = ZERO_BYTE;
    return 1;
int index = offset + length;
int scale = v.scale();
int expOffset = scale % 2 * (scale < 0 ? -1 : 1);
...