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



Home Java Java-bigdecimal Java bigdecimal unscaledValue example

Related Tutorials


 
 

Share on Google+Share on Google+

Java bigdecimal unscaledValue example

Advertisement
Example below demonstrates working of bigdecimal class unscaledValue method. Method returns biginteger values.

Java bigdecimal unscaledValue example

     

Example below demonstrates working of bigdecimal class unscaledValue method. Method returns biginteger values.  An un scaled value of  the bigdecimal object  is returned as biginteger object value.

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

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

Java_bigdecimal_unscaledValue.java

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

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

  MathContext mc = new MathContext(0);
  mc = mc.DECIMAL32;
  BigDecimal nc = new BigDecimal(00.552, mc);

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

  nc = new BigDecimal(2.150, mc);
  System.out.println("\n BigDecimal value :" + nc
  "\nmethod generating result :" + nc.unscaledValue());

  nc = new BigDecimal(-263.41, mc);
  System.out.println("\n BigDecimal value :" + nc
  "\nmethod generating result :" + nc.unscaledValue());

  nc = new BigDecimal(2.12000, mc);

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

  }
}

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 unscaledValue example  

Post your Comment


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