Java – How to Negate a BigDecimal in Java ?


Grammarly

More than 40 Lakhs Students and Professionals use Grammarly for their spell and grammar checks. You can register and try for free.

Problem Statement

You need to negate the value of the BigDecimal datatype in your java program.

Solution

Use the negate method defined in the BigDecimal class as shown below.

import java.math.BigDecimal;

public class Main {

    public static void main(String[] args) {

        System.out.println("Abundantcode.com Java Tutorials");

        BigDecimal input1 = new BigDecimal(10102);
        BigDecimal output = input1.negate();
        System.out.println(output);

    }
}


The output of the above program is

Abundantcode.com Java Tutorials

-10102


Grammarly

More than 40 Lakhs Students and Professionals use Grammarly for their spell and grammar checks. You can register and try for free.
%d bloggers like this: