logo

Adding two BigDecimal values

Java Code Examples for java.math.BigDecimal.add()

This method to add two BigDecimal values.

package simplesolution.dev;

import java.math.BigDecimal;

public class BigDecimalAddExamples {

    public static void main(String... args) {
        BigDecimal bigDecimal1 = new BigDecimal("10.001");
        BigDecimal bigDecimal2 = new BigDecimal("10.002");

        BigDecimal result = bigDecimal1.add(bigDecimal2);

        System.out.println(bigDecimal1);
        System.out.println(bigDecimal2);
        System.out.println(result);
    }
}

Happy Coding 😊

Tags: