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

BigDecimalbytesToBigDecimal(byte[] buffer)
This function converts the bytes in a byte array to its corresponding big decimal value.
String string = bytesToString(buffer);
return new BigDecimal(string);
BigDecimalbyteToBigDecimal(byte[] raw)
This method will convert a byte value back to big decimal value
int scale = (raw[0] & 0xFF);
byte[] unscale = new byte[raw.length - 1];
System.arraycopy(raw, 1, unscale, 0, unscale.length);
BigInteger sig = new BigInteger(unscale);
return new BigDecimal(sig, scale);
BigDecimalbyteToBigDecimal(byte[] raw)
This method will convert a byte value back to big decimal value
int scale = (raw[0] & 0xFF);
byte[] unscale = new byte[raw.length - 1];
System.arraycopy(raw, 1, unscale, 0, unscale.length);
BigInteger sig = new BigInteger(unscale);
return new BigDecimal(sig, scale);
BigDecimalcastBigDecimal(Object o)
Casts a value to a BigDecimal.
if (o == null) {
    return null;
if (o instanceof BigDecimal) {
    return (BigDecimal) o;
if (o instanceof Number) {
    return BigDecimal.valueOf(((Number) o).doubleValue());
...
BigDecimalcastToBigDecimal(Object value)
cast To Big Decimal
if (value == null) {
    return null;
if (value instanceof BigDecimal) {
    return (BigDecimal) value;
if (value instanceof BigInteger) {
    return new BigDecimal((BigInteger) value);
...
BigDecimalconvertNumberToBigDecimal(Number aNumber)
convert Number To Big Decimal
return new BigDecimal(aNumber.toString());
ListdoubleArrayToBigDecimalList(double[] array)
double Array To Big Decimal List
List<BigDecimal> list = new ArrayList<BigDecimal>();
for (double item : array) {
    list.add(new BigDecimal(item));
return list;
BigDecimaldoubleToBigDecimal(double amountAsDouble)
double To Big Decimal
return new BigDecimal(amountAsDouble).setScale(DECIMAL_SCALE, ROUNDING_MODE);
BigDecimaldoubleToBigDecimal(double dd)
double To Big Decimal
BigDecimal bd;
try {
    bd = BigDecimal.valueOf(dd).setScale(SCALE, BigDecimal.ROUND_HALF_UP);
} catch (Exception e) {
    bd = BigDecimal.valueOf(0d);
return bd;
BigDecimallongToBigDecimal(long amountAsSatoshis)
long To Big Decimal
return new BigDecimal(amountAsSatoshis).divide(SATOSHIS);