Home Java Java-bigdecimal Java bigdecimal shortValueExact
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

Java bigdecimal shortValueExact

Advertisement
In this example working of Java bigdecimal class shortValueExact method is demonstrated.

Java bigdecimal shortValueExact

     

In this example working of  Java bigdecimal class shortValueExact method  is demonstrated.  Method return type is short therefore it will return only short values. Method converts bigdecimal in to short data type value. In the example one bigdecimal object  mass is created.   Method throws NumberFormatException if it finds any other value to be converted in to short  other than integers and decimals. Method also throws ArithmeticException if the value contains non-zero fractional part.

Syntax for using the method: public short

shortValueExact()

short sh = this.object.shortValueExact();

Java_bigdecimal_shortValueExact.java

import java.math.BigDecimal;

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

  BigDecimal mass = new BigDecimal(5648);
  short shortValueExact;
  shortValueExact = mass.shortValueExact();
  System.out.println("BigDecimal value : " +
  "" + mass
  "\nmethod converted short value" +
  " : " + shortValueExact);

  float valuef = 3625;
  mass = new BigDecimal(valuef);
  System.out.println("\nmass object value : " +
  "" + mass + "\nmethod generated " +
  "short value : " +
  "" + mass.shortValueExact());

  double valueD = 2003;
  Double doubleObj = new Double(valueD);
  mass = new BigDecimal(doubleObj);
  System.out.println("\nmass object value :" +
  " " + mass  + "\nmethod generated " +
  "short value : " + mass.shortValueExact());

  }
}

Download the code

Advertisements

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

Ask Questions?    Discuss: Java bigdecimal shortValueExact  

Post your Comment


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