Here you can find the source of getBigDecimal(Object v, BigDecimal defaultValue)
public static BigDecimal getBigDecimal(Object v, BigDecimal defaultValue)
//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; } }