Home Java Java-bigdecimal Java bigdecimal precision example



Java bigdecimal precision example
Posted on: November 24, 2008 at 12:00 AM
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

Related Tags for Java bigdecimal precision example:
cgitclassobjectiomethodtypedecimalgdvaluenumberreturnintthisprecisionexamplescaleworkbigdecimalexamcibieitdemopeimincalasmnttrcajclworkingemdigitsdigbigmeobjratexaxampsurnatkismplprestrvascassthstalujeigdpleplprono


More Tutorials from this section

Ask Questions?    Discuss: Java bigdecimal precision example  

Post your Comment


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

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.