Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Java Java-bigdecimal Java bigdecimal precision example

Related Tutorials


 
 

Share on Google+Share on Google+

Java bigdecimal precision example

Advertisement
In this example, bigdecimal class precision method working is demonstrated. Method return type is int. Method returns the number of digits of an unscaled object value.

Java bigdecimal precision example

     

In this example, bigdecimal class precision method working is demonstrated. Method return type is int. Method returns the number of  digits of an unscaled object value.

Method throws NumberFormatException if it finds value other than integer and double. 

Syntax for using the method : public int precision()
BigDecimal objects with names x;
System.out.print(x.precision());
or
int i = x.precision();

Note: Method generates value 1 for this.object value zero.

Java_bigdecimal_precision.java

import java.math.BigDecimal;

public class Java_bigdecimal_precision {
  public static void main(String args[]) {
  BigDecimal honey = new BigDecimal("12"),
  storm = new BigDecimal(0000);
  System.out.println("honey object value :" +
  " " + honey);
  System.out.println("method generated " +
  "result : " + honey.precision());

  System.out.println("\nstorm object value" +
  " : " + storm);
  System.out.println("method generated " +
  "result : " + storm.precision());

  honey = new BigDecimal(-2321);
  storm = new BigDecimal(-5.1);

  System.out.println("\nhoney object value " +
  ": " + honey);
  System.out.println("method generated " +
  "result : " + honey.precision());

  System.out.println("\nstorm object value " +
  ": " + storm);
  System.out.println("method generated " +
  "result : " + storm.precision());

  storm = new BigDecimal(-5.1);
  storm = new BigDecimal(storm.floatValue());
  System.out.println("\nstorm object value " +
  ": " + storm);
  System.out.println("method generated " +
  "result : " + storm.precision());

  }
}

Download the code

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: November 24, 2008

Related Tutorials

Discuss: Java bigdecimal precision example  

Post your Comment


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