Bigdecimal takes the value of a string

Asked

Viewed 208 times

0

I have the following question, how to accomplish the sum of a BigDecimal with a String.

String a = "8";
BigDecimal b = new BigDecimal(2);

It would look something like this? b.add(a);

Note: I need the logic to be this, I just need to know how to assign the value of a BigDecimal of a variable String.

1 answer

5


String a = "8";
BigDecimal a2 = new BigDecimal(a);
BigDecimal b = new BigDecimal(2);
BigDecimal c = b.add(a2);
  • It does not work, when giving the value of the variable a to Bigdecimal a2 it gives error

  • @Werikyalphazero What mistake?

  • I’m the one who screwed up, buddy. Thank you very much

Browser other questions tagged

You are not signed in. Login or sign up in order to post.