Online Training Spring Hibernate Training in Delhi R Programming Training Course Big Data and Hadoop Training Java Training

Java BigDecimal divideAndRemainder example

Example below demonstrates, working of divideAndRemainder(BigDecimal divisor) method. Method divides the bigdecimal class object value on which it is invoked, by the bigdecimal class object value passed inside the parentheses of the method.

Ads

Tutorials   
Java Bigdecimal Java bigdecimal toBigIntegerExact example Java bigdecimal shortValue example Java bigdecimal shortValueExact Java bigdecimal signum example Java bigdecimal stripTrailingZeros example Java bigdecimal subtract Java bigdecimal subtract method example Java bigdecimal toBigInteger example Java bigdecimal toEngineeringString example Java bigdecimal toPlainString example Java bigdecimal toString example Java bigdecimal ulp example Java bigdecimal unscaledValue example Java bigdecimal valueOf double example Java bigdecimal valueOf long example Java bigdecimal valueOf long method Java bigdecimal setScale method example Java bigdecimal setScale example Java bigdecimal scaleByPowerOfTen example Java bigdecimal scale example Java bigdecimal round example Java bigdecimal remainder method example Java bigdecimal remainder example Java bigdecimal precision example Java bigdecimal pow method example Java bigdecimal pow example Java bigdecimal plus method example Java bigdecimal plus example Java bigdecimal negate method example Java bigdecimal negate example Java bigdecimal multiply method example Java bigdecimal multiply example Java BigDecimal movePointRight example Java bigdecimal movePointLeft example Java bigdecimal min example Java bigdecimal max example Java BigDecimal divideAndRemainder example Java BigDecimal divideAndRemainder method example Java BigDecimal divide examples Java BigDecimal divideToIntegral example Java BigDecimal divideToIntegral method example Java BigDecimal doubleValue example Java BigDecimal equals example Java BigDecimal hashCode example Java BigDecimal intValue example Java BigDecimal intValueExact example Java BigDecimal longValue example Java BigDecimal longValueExact example Java BigDecimal abs example
Ads

Java BigDecimal divideAndRemainder example

     

Example below demonstrates, working of divideAndRemainder(BigDecimal divisor) method. Method divides the bigdecimal  class object value on which it is invoked, by the bigdecimal class object value passed inside the parentheses of the method.  Shortly it can said as method divides this.object value by the value of object passed.  Method return type is an bigdecimal array of length two(2). This array contains the method generated results. At array index zero(array[0]) method generated first result, 'quotient' is located & at array index one(array[1])  method generated second result, 'remainder' is located. 

The first result 'quotient' will always possess integer format. This means method will only generate the integer part, i.e. the portion of 'quotient' before decimal. 

Method will generate the remainder also as the second(array[1]) element of bigdecimal array[]. 

Method throws Arithmetic Exception when the divisor value is equal to zero.

Syntax for using the method:
public BigDecimal[] divideAndRemainder(BigDecimal divisor)

bigdecimal_objectName = dividendName.divideAndRemainder(divisor)

Java_divideAndRemainder_BigDecimal_divisor.java

import java.math.BigDecimal;
import java.text.NumberFormat;
import java.util.Locale;

public class Java_divideAndRemainder_BigDecimal_divisor {
  public static void main(String args[]) {
  System.out.println("");

  byte byte_value = 5;
  short short_value = 3125;

  BigDecimal obj_0 = new BigDecimal(short_value),
  obj_1 = new BigDecimal(byte_value);

  // constructing BigDecimal array
  BigDecimal array[] = obj_0.divideAndRemainder(obj_1);

  /* Here the element at index one is the remainder &
  the element at index at zero is the quotient's 
  integer part i.e. value before decimal*/
  System.out.println("Quotient's integer part" +
  " : " + array[0"\tRemainder : "
  + array[1]);

  byte_value = 7;  short_value = 22;
  BigDecimal rose = new BigDecimal(short_value),
  tech = new BigDecimal(byte_value),
  ant[] = rose.divideAndRemainder(tech);

  System.out.println("Quotient's integer" +
  " part : " + ant[0"\tRemainder :" +
  " " + ant[1]);

  
  }
}

Download the code

Advertisements

Share on Google+Share on Google+

Java BigDecimal divideAndRemainder example

Posted on: November 21, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

 

Discuss: Java BigDecimal divideAndRemainder example  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0

Ads

 

Ads