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

voidbigDecimalProperty(ObjectNode node, String propertyName, BigDecimal propertyValue)
Sets the value of a property for a given json node.
if (propertyValue == null) {
    return;
if (isIntegerValue(propertyValue)) {
    node.set(propertyName, factory.numberNode(propertyValue.toBigInteger()));
} else {
    node.set(propertyName, factory.numberNode(propertyValue));
booleanbyteOverflow(BigDecimal value)
Checks for overflow when converting a BigDecimal to a byte.
return value.compareTo(BIGDECIMAL_BYTE_MAX) > 0 || value.compareTo(BIGDECIMAL_BYTE_MIN) < 0 ? false : true;
BigDecimalcloneBigDecimal(BigDecimal bdOriginal)
Echtes Klonen von BigDecimals.
if (bdOriginal == null) {
    return null;
} else {
    return bdOriginal.setScale(bdOriginal.scale());
JsonNumbercreateJsonNumber(BigDecimal d)
create Json Number
return new JsonNumber() {
    @Override
    public boolean isIntegral() {
        return d.scale() == 0;
    @Override
    public int intValue() {
        return d.intValue();
...
StringcreateReconFileHeader(int totalCount, BigDecimal totalAmount)
create Recon File Header
StringBuilder sb = new StringBuilder();
sb.append("0").append(SEPERATOR).append(SEPERATOR).append(totalCount).append(SEPERATOR).append(totalAmount)
        .append(SEPERATOR).append(totalCount).append(SEPERATOR).append(totalAmount).append(LINECHANGE);
;
return sb.toString();
BigDecimalcuberoot(BigDecimal b)
cuberoot
MathContext mc = new MathContext(40);
BigDecimal x = new BigDecimal("1", mc);
for (int i = 0; i < ITER; i++) {
    x = x.subtract(
            x.pow(3, mc).subtract(b, mc).divide(new BigDecimal("3", mc).multiply(x.pow(2, mc), mc), mc),
            mc);
return x;
...
StringcurrencyFormat(BigDecimal value, char decimalDelimiter)
currency Format
long totalCent = value.multiply(new BigDecimal(100)).intValue();
long eurOnly = value.longValue();
long centOnly = Math.abs(totalCent % 100);
StringBuffer res = new StringBuffer();
res.append(eurOnly);
res.append(decimalDelimiter);
if (centOnly < 10) {
    res.append('0');
...
intdecimalDigits(BigDecimal d)
The number of decimal digits.
return Math.max(0, d.stripTrailingZeros().scale());
BigDecimaldeserializeBigDecimalFromString(String decimal)
Deserialize a Volt fixed precision and scale 16-byte decimal from a String representation
if (decimal == null) {
    return null;
final BigDecimal bd = new BigDecimal(decimal);
if (bd.scale() > 12) {
    throw new IOException("Decimal " + bd + " has more then 12 digits of scale");
if (bd.precision() > 38) {
...
BigDecimalexp(BigDecimal power)
Raises e to the power of the input big decimal.
int precision = power.precision();
MathContext context = new MathContext(precision, RoundingMode.HALF_DOWN);
return exp(power, context);