How to add BigDecimal in Java?

Ads
Ads

How to add BigDecimal in Java?


Java Coder
How to add BigDecimal in Java?
1 Answer(s)      a year ago
Posted in : Java Beginners
Ads

Hi,

I have two BigDecimal variables. I want to add these two values.

How to add BigDecimal in Java?

Thanks

View Answers

April 16, 2017 at 5:02 PM


Hello,

I will show you how you can add two BigDecimal?

Suppose you have following two variables:

BigDecimal var1 = BigDecimal(1.02);
BigDecimal var2 = BigDecimal(5.08);

There is method of BigDecimal named add() which can be used to add. Here is the example of adding two:

BigDecimal resule = var2.add(var1);

Check tutorial at Add two big numbers.

Thanks


Ads