Java BigDecimal Create getBigDecimal(Object v, BigDecimal defaultValue)

Here you can find the source of getBigDecimal(Object v, BigDecimal defaultValue)

Description

get Big Decimal

License

Apache License

Declaration

public static BigDecimal getBigDecimal(Object v, BigDecimal defaultValue) 

Method Source Code

//package com.java2s;
/*******************************************************************************
* Copyright 2007-2013 See AUTHORS file.//from   w  w  w .  j av  a  2 s .c om
 * 
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* 
*   http://www.apache.org/licenses/LICENSE-2.0
* 
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/

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

public class Main {
    public static final String VALUE_BLANK = "";

    public static BigDecimal getBigDecimal(Object v, BigDecimal defaultValue) {
        if (v == null || VALUE_BLANK.equals(v)) {
            return null;
        } else if (v instanceof BigDecimal) {
            return (BigDecimal) v;
        } else if (v instanceof String) {
            return new BigDecimal((String) v);
        } else if (v instanceof Integer) {
            return new BigDecimal((Integer) v);
        } else if (v instanceof Boolean) {
            return new BigDecimal(((Boolean) v) ? 1 : 0);
        } else if (v instanceof Byte) {
            return new BigDecimal((Byte) v);
        } else if (v instanceof BigInteger) {
            return new BigDecimal((BigInteger) v);
        } else if (v instanceof Double) {
            return new BigDecimal((Double) v);
        } else if (v instanceof Float) {
            return new BigDecimal((Float) v);
        } else if (v instanceof Short) {
            return new BigDecimal((Short) v);
        }

        return defaultValue;
    }
}

Related

  1. getBigDecimal(Map map, String attr)
  2. getBigDecimal(Number number)
  3. getBigDecimal(Object number)
  4. getBigDecimal(Object o)
  5. getBigDecimal(Object o)
  6. getBigDecimal(Object value)
  7. getBigDecimal(Object value)
  8. getBigDecimal(String aInput)
  9. getBigDecimal(String value)