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

Java BigInteger long

Example below illustrates the bigdecimal class divide(BigDecimal divisor) method working.

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 BigInteger long

     

Example below illustrates the bigdecimal class divide(BigDecimal divisor) method working. In the example method divides the bigdecimal object value in which it is invoked by the bigdecimal object value passed inside its parentheses. The scale of the quotient is the scale of the value of object in which the method is invoked minus the scale of the value of object specified. In short scale of quotient is (this.object value scale) - (object.value scale). Moreover the result generated has to be stored by some bigdecimal object as this method returns bigdecimal object type values only.

Method throws an Arithmetic Exception when a non-terminating quotient is generated. This means the quotient does not possess any termination point in to its fractional part. Method throws NumberFormatException if it finds a value other than a integer or double value.

Syntax for using the method:

System.out.println(bigdecimal_objectName.divide(BigDecimal divisor)); 
  or
BigDecimal x = this.object.divide(divisor);

Java_BigDecimal_divide_BigDecimal_Divisor.java

import java.math.BigDecimal;
import java.math.BigInteger;
import java.text.NumberFormat;

public class Java_BigDecimal_divide_BigDecimal_Divisor {
  public static void main(String args[]) {

  String str = "200", cv = "2";

  BigInteger in = new BigInteger(str);
  BigDecimal Divident_0 = new BigDecimal(in)
  Divisor_0 = new BigDecimal(cv)
  Quotient_0 = new BigDecimal(
  Divident_0.divide(Divisor_0).toString()),
  Remainder_0 = new BigDecimal(Integer.parseInt(str)
  % Integer.parseInt(cv));
  
  System.out.println("Quotient : " + Quotient_0 +
  "\nRemainder : "+ Remainder_0);

  // Similarly
  double dear = 85.6, beloved = 70;

  BigDecimal Divident_1 = new BigDecimal(dear)
  Divisor_1 = new BigDecimal(beloved)
  Quotient_1 = new BigDecimal(
  Divident_1.divide(Divisor_1).toString())
  Remainder_1 = new BigDecimal(dear % beloved);

  System.out.println("\nUnrounded values");
  System.out.println("Quotient : " +
  Quotient_1 + "\nRemainder : "+ Remainder_1);

  NumberFormat Fraction = NumberFormat.getInstance();
  Fraction.setMinimumFractionDigits(3);

  System.out.println("\nRounded values");
  System.out.println("Quotient : " 
  + Fraction.format(Quotient_1)
  "\nRemainder : " + Fraction.format(Remainder_1));

  }
}

Download the code

Advertisements

Online Training Classes

Share on Google+Share on Google+

Java BigInteger long

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

Advertisements

Ads
 

Discuss: Java BigInteger long  

Post your Comment


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

Ads

 

Ads