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