Home > Blockchain >  I cannot add two BigDecimal objects
I cannot add two BigDecimal objects

Time:10-01

When I want to add two BigDecimal objects together

public void addBalanceWallet(BigDecimal balanceWallet) {
        this.balanceWallet.add(balanceWallet);
}

There is no effect. Additionally, the IDE shows enter image description here

Why can't I add these two objects together?

CodePudding user response:

You are not assigning the return value (which is the actual result of the addition) to anything and thus the "Result (...) is ignored" message. I guess you want to do the following:

public void addBalanceWallet(BigDecimal balanceWallet) {
    this.balanceWallet = this.balanceWallet.add(balanceWallet);
}

CodePudding user response:

You have to save the return value. For example:

public BigDecimal addBalanceWallet(BigDecimal balanceWallet) {
        return this.balanceWallet.add(balanceWallet);
}

And afterwards:

BigDecimal addResult = this.balanceWallet.addBalanceWallet(some_big_decimal)
  •  Tags:  
  • java
  • Related