logo

Subtract two BigDecimal values

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

This method to substact two BigDecimal values.

package simplesolution.dev;

import java.math.BigDecimal;

public class BigDecimalSubtractExamples {

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

        BigDecimal result = bigDecimal1.subtract(bigDecimal2);

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

Happy Coding 😊

Tags: