Java Utililty Methods BigDecimal

List of utility methods to do BigDecimal

Description

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

Method

intmoveRight(BigDecimal value, int offset)
move Right
if (null == value) {
    return 0;
return value.movePointRight(offset).intValue();
intnullSafeCompare(BigDecimal pPremierNombre, BigDecimal pSecondNombre)
null Safe Compare
if (pPremierNombre == pSecondNombre) 
    return 0;
if (null == pPremierNombre) {
    return -1;
if (null == pSecondNombre) {
...
StringnumberToWordsWithDecimal(BigDecimal value)
number To Words With Decimal
final String integerText = numberToWords(value.longValue(), false);
String decimalText = value.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString();
decimalText = decimalText.substring(decimalText.indexOf(".") + 1);
return integerText + " and " + decimalText + "/100";
BigDecimalnvl(final BigDecimal bigDecimal)
Returns zero when the given BigDecimal is null
return bigDecimal == null ? BigDecimal.ZERO : bigDecimal;
BigDecimalnvlZero(BigDecimal num)
nvl Zero
return num == null ? BigDecimal.ZERO : num;
BigDecimalobjectToBigDecimal(Object object)
Supports any object which toString method return a numeric as String.
if (object == null) {
    return null;
try {
    return new BigDecimal(object.toString());
} catch (NumberFormatException nfe) {
    return null;
BigDecimalobjToBigDecimal(Object obj)
obj To Big Decimal
BigDecimal bigDec = null;
if (obj != null) {
    bigDec = (BigDecimal) obj;
return bigDec;
StringPackUnit2Uom(BigDecimal packUit, String eachUnitName)
Pack Unit Uom
if (eachUnitName.compareTo("EA") == 0) {
    return String.format("H%02d", packUit.intValue());
} else if (eachUnitName.compareTo("KG") == 0) {
    return String.format("H%.4fK", packUit.floatValue());
} else if (eachUnitName.compareTo("G") == 0) {
    return String.format("H%.4fG", packUit.floatValue());
} else {
    return String.format("H%.4fN", packUit.floatValue());
...
BigDecimalpercent0(final BigDecimal c, final BigDecimal percent)
percent
BigDecimal res = c.multiply(percent);
BigDecimal l100 = new BigDecimal("100");
BigDecimal res1 = res.divide(l100, 2, 0);
return res1;
Stringpercentage(BigDecimal bd)
percentage
return bd.multiply(HUNDRED).setScale(1, RoundingMode.HALF_UP).toString();