Example usage for java.math BigDecimal toBigInteger

List of usage examples for java.math BigDecimal toBigInteger

Introduction

In this page you can find the example usage for java.math BigDecimal toBigInteger.

Prototype

public BigInteger toBigInteger() 

Source Link

Document

Converts this BigDecimal to a BigInteger .

Usage

From source file:org.plasma.sdo.helper.DataConverter.java

public Object fromDecimal(Type targetType, BigDecimal value) {
    DataType targetDataType = DataType.valueOf(targetType.getName());
    switch (targetDataType) {
    case Decimal:
        return value;
    case Double:
        return new Double(value.doubleValue());
    case Float:
        return new Float(value.floatValue());
    case Int://from  w  ww  . j a  v  a2s . c o  m
        return new Integer(value.intValue());
    case Long:
        return new Long(value.longValue());
    case Integer:
        return value.toBigInteger();
    case String:
        // as per spec: ('+'|'-')? [0-9]* ('.'[0-9]*)? (('E'|'e') ('+'|'-')? [0-9]+)?
        /*
         *  [123,0]      "123"
         *   [-123,0]     "-123"
         *   [123,-1]     "1.23E+3"
         *   [123,-3]     "1.23E+5"
         *   [123,1]      "12.3"
         *   [123,5]      "0.00123"
         *   [123,10]     "1.23E-8"
         *   [-123,12]    "-1.23E-10"
         */
        return value.toString();
    default:
        throw new InvalidDataConversionException(targetDataType, DataType.Decimal, value);
    }
}

From source file:org.apache.openjpa.jdbc.sql.DBDictionary.java

/**
 * Convert the specified column of the SQL ResultSet to the proper
 * java type./*from   w ww  .  j ava  2  s.  co  m*/
 */
public BigInteger getBigInteger(ResultSet rs, int column) throws SQLException {
    if (storeLargeNumbersAsStrings) {
        String str = getString(rs, column);
        return (str == null) ? null : new BigDecimal(str).toBigInteger();
    }
    BigDecimal bd = getBigDecimal(rs, column);
    return (bd == null) ? null : bd.toBigInteger();
}