Java.math.BigDecimal.negate() Method

Advertisements


Description

The java.math.BigDecimal.negate() returns a BigDecimal whose value is (-this), and whose scale is this.scale().

Declaration

Following is the declaration for java.math.BigDecimal.negate() method

public BigDecimal negate()

Parameters

  • NA

Return Value

This method returns the negative value of the object i.e -this

Exception

  • NA

Example

The following example shows the usage of math.BigDecimal.negate() method

package com.tutorialspoint;

import java.math.*;

public class BigDecimalDemo {

   public static void main(String[] args) {

      // create 2 BigDecimal objects
      BigDecimal bg1, bg2;

      // assign value to bg1
      bg1 = new BigDecimal("40.1264");

      // assign negate value of bg1 to bg2
      bg2 = bg1.negate();

      String str = "Negated value of " + bg1 + " is "+ bg2;

      // print bg1 and bg2 values
      System.out.println( str );
   }
}

Let us compile and run the above program, this will produce the following result:

Negated value of 40.1234 is -40.1264



Advertisements
Advertisements