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

byte[]bigDecimalToByte(BigDecimal num)
This method will convert a big decimal value to bytes
BigInteger sig = new BigInteger(num.unscaledValue().toString());
int scale = num.scale();
byte[] bscale = new byte[] { (byte) (scale) };
byte[] buff = sig.toByteArray();
byte[] completeArr = new byte[buff.length + bscale.length];
System.arraycopy(bscale, 0, completeArr, 0, bscale.length);
System.arraycopy(buff, 0, completeArr, bscale.length, buff.length);
return completeArr;
...
byte[]bigDecimalToBytes(BigDecimal decimal)
This function converts a big decimal to its corresponding byte array format.
String string = decimal.toString();
return stringToBytes(string);
StringbigDecimalToDbString(BigDecimal bd)
Converts the BigDecimal bd into something formatted properly for MySQL.
return (bd == null) ? "NULL" : bd.toString();
IntegerbigDecimalToInteger(BigDecimal value)
big Decimal To Integer
if (value != null) {
    return new Integer(value.intValue());
return null;
StringbigDecimaltoJSONString(Object obj)
bigDecimaltoJSONString
BigDecimal number = (BigDecimal) obj;
return number.toString();
LongbigDecimalToLong(BigDecimal bigDecimal)
big Decimal To Long
bigDecimal.setScale(DECIMAL_SCALE, ROUNDING_MODE);
return bigDecimal.multiply(SATOSHIS).longValue();
LongbigDecimalToLong(BigDecimal value)
big Decimal To Long
return value.setScale(0, BigDecimal.ROUND_HALF_UP).longValue();
StringbigDecimalToStellarBalance(final BigDecimal balance)
big Decimal To Stellar Balance
return balance.toString();
StringbigDecimalToString(BigDecimal bigDecimal)
big Decimal To String
if (bigDecimal == null) {
    return "";
return bigDecimal.toString();
StringbigDecimalToString(BigDecimal dec)
big Decimal To String
if (dec == null) {
    return "0";
if (dec.toString().length() < 10) {
    return dec.toString();
return dec.toString().substring(0, 10) + dec.toString().substring(dec.toString().length() - 6);