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

Java bigdecimal ulp example

Example below demonstrates working of bigdecimal class ulp method. Method returns bigdecimal values.

Java bigdecimal ulp example

                         

Example below demonstrates working of bigdecimal class ulp method. Method returns  bigdecimal values.  Method returns the size of an ulp. which is the size of a unit at the last place of the bigdecimal object value. 

Method returns +1 for a positive bigdecimal value. Actually this ulp size is the difference between the bigdecimal value and  just the next number after the bigdecimal value. For example,  if the bigdecimal value is 4 then its next value is 5, and there difference that is one, is the value that the ulp method generates.

The scale of the result will be same as that of the this.object value.

Method represents the bigdecimal object value in scientific notations if required. For example if method generates 5E-5, then it means 5 * ten to the power minus 5.

Method generates NumberFormatException, if it finds the bigdecimal value other than integers and double types values. 

Syntax for using the method: public BigDecimal ulp() 
Suppose we have bigdecimal objects x & y;
        then y = x.ulp();
System.out.println(y); 

Java_bigdecimal_ulp.java

import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.MathContext;

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

    BigDecimal nc = new BigDecimal(0);

    System.out.println(" BigDecimal value :" + nc
        "\nmethod generating result :" + nc.ulp());

    nc = new BigDecimal(2);
    System.out.println("\n BigDecimal value :" + nc
        "\nmethod generating result :" + nc.ulp());

    nc = new BigDecimal(3.1);
    System.out.println("\n BigDecimal value :" + nc
        "\nmethod generating result :" + nc.ulp());

    nc = new BigDecimal(4000);
    System.out.println("\n BigDecimal value :" + nc
        "\nmethod generating result :" + nc.ulp());

  }
}

Download the code

                         

» View all related tutorials
Related Tags: c class object method decimal gd trac value return this invoke if ie example work bigdecimal values exam ci bi

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 
 
Tell A Friend
Your Friend Name

 

 
Recently Viewed
Software Solutions
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

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

Copyright © 2008. All rights reserved.