Home Java Java-bigdecimal Java bigdecimal unscaledValue example



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

Related Tags for Java bigdecimal unscaledValue example:
cclassobjectintegermethoddecimalgdvaluereturnintbigintegerexamplescaleworkbigdecimalvaluesexamcibiedemoimincalasmnttrcajclesbigintworkingembigmeobjrateratesxaxampsurnginatkismplstrvascassthbelostalujeigdpleplono


More Tutorials from this section

Ask Questions?    Discuss: Java bigdecimal unscaledValue 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.