Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Java BigInteger long 
 

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

 

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

                         

» View all related tutorials
Related Tags: java c exception forms class orm form object io objects integer method format type double decimal gd value number name

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.