Метод BigDecimal plus () в Java

Опубликовано: 13 Февраля, 2022
  1. The java.math.BigDecimal.plus() is an inbuilt method in java that returns a BigDecimal whose value is (+this), and whose scale is this.scale(). This method, which simply returns this BigDecimal is included for symmetry with the unary minus method negate().

    Syntax:

    public BigDecimal plus()

    Parameters: The function does not accepts any parameter.

    Return value: This method returns the object value i.e., this.

    Below program illustrates the working of the above metioned method:
    Program 1:

    // Java program to demonstrate the
    // plus() method
      
    import java.math.*;
      
    public class Gfg {
      
        public static void main(String[] args)
        {
      
            // Assign value to b1
            BigDecimal b1 = new BigDecimal("-45.652");
      
            // Assign the result of plus method on
            // BigDecimal Objects b1 to b2
            BigDecimal b2 = b1.plus();
      
            // Print the value of b2
            System.out.println("The value of the BigDecimal is " + b2);
        }
    }
    Output:

    The value of the BigDecimal is -45.652