List of utility methods to do BigDecimal to
Object | toObject(BigDecimal value) to Object return value;
|
BigDecimal | toPercent(final BigDecimal decimalValue, final MathContext mathCntext) to Percent return convertNullToZero(decimalValue).divide(ONE_HUNDRED, mathCntext);
|
String | toScientificNotation(BigDecimal bd) Formats a BigDecimal value to a string in scientific notation For example
If bd has a precision higher than 20, this method will truncate the output string to have a precision of 20 (no rounding will be done, just a truncate).
final int truncateAt = 20; String unscaled = bd.unscaledValue().toString(); if (bd.signum() < 0) { unscaled = unscaled.substring(1); int len = unscaled.length(); int scale = bd.scale(); int e = len - scale - 1; ... |
BigDecimal | toSimpleBigDecimal(Object num) to Simple Big Decimal try { return num != null ? new BigDecimal(num.toString()) : null; } catch (Exception ignored) { return null; |
String | toString(BigDecimal num) to String if (num == null) { return "0"; } else { return num.setScale(2).toString(); |
String | toString(BigDecimal value, int numberDecimalPlaces) to String String newStr = null; if (value != null) { try { newStr = String.format("%." + numberDecimalPlaces + "f", value); int posCorte = newStr.lastIndexOf("."); if (posCorte >= 0) { String decimal = newStr.substring(posCorte + 1); if (decimal.length() > numberDecimalPlaces) { ... |
String | toString(final BigDecimal dec) to String return dec.toPlainString();
|
String | toUnsignedString(BigDecimal bigDecimal, int shift) to Unsigned String BigDecimal divisor = new BigDecimal(shift); Deque<Character> numberDeque = new ArrayDeque<Character>(); do { BigDecimal[] ba = bigDecimal.divideAndRemainder(divisor); bigDecimal = ba[0]; numberDeque.addFirst(digits[ba[1].intValue()]); } while (bigDecimal.compareTo(BigDecimal.ZERO) > 0); StringBuilder builder = new StringBuilder(); ... |