Java.math.BigDecimal.divideToIntegralValue() Method


Advertisements


Description

The java.math.BigDecimal.divideToIntegralValue(BigDecimal divisor) returns a BigDecimal whose value is the integer part of the quotient (this / divisor) rounded down. The preferred scale of the result is (this.scale() - divisor.scale()).

Declaration

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

public BigDecimal divideToIntegralValue(BigDecimal divisor)

Parameters

divisor − value by which this BigDecimal is to be divided.

Return Value

This method returns the integer part of this / divisor.

Exception

ArithmeticException − If divisor == 0.

Example

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

package com.tutorialspoint;

import java.math.*;

public class BigDecimalDemo {

   public static void main(String[] args) {

      // create 3 BigDecimal objects
      BigDecimal bg1, bg2,bg3;

      bg1 = new BigDecimal("99.8");
      bg2 = new BigDecimal("3");

      // divide bg1 with bg2
      bg3 = bg1.divideToIntegralValue(bg2);

      String str = "Integer part of division result is " +bg3;

      // print bg3 value
      System.out.println( str );
   }
}

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

Integer part of division result is 33.0

java_math_bigdecimal.htm

Advertisements