Convert BigDecimal to primitive data types

ReturnMethodSummary
bytebyteValueExact()Converts this BigDecimal to a byte, checking for lost information.
doubledoubleValue()Converts this BigDecimal to a double.
floatfloatValue()Converts this BigDecimal to a float.
intintValue()Converts this BigDecimal to an int.
intintValueExact()Converts this BigDecimal to an int, checking for lost information.
longlongValue()Converts this BigDecimal to a long.
longlongValueExact()Converts this BigDecimal to a long, checking for lost information.
shortshortValueExact()Converts this BigDecimal to a short, checking for lost information.
BigIntegertoBigInteger()Converts this BigDecimal to a BigInteger.
BigIntegertoBigIntegerExact()Converts this BigDecimal to a BigInteger, checking for lost information.

import java.math.BigDecimal;

public class Main {

  public static void main(String[] args) {
    BigDecimal first = new BigDecimal(-1f);
    System.out.println(first.floatValue());

  }
}

The output:


-1.0
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.