Here you can find the source of toBigDecimal(Object obj)
public static BigDecimal toBigDecimal(Object obj)
//package com.java2s; //License from project: Apache License import java.math.BigDecimal; public class Main { private static final Object NULL = null; public static BigDecimal toBigDecimal(Object obj) { if (isNull(obj)) { return getNull(); }//from ww w. j av a 2 s .c om if (obj instanceof BigDecimal) { return (BigDecimal) obj; } if (obj instanceof Integer) { return new BigDecimal((Integer) obj); } if (obj instanceof Long) { return new BigDecimal((Long) obj); } if (obj instanceof Double) { return new BigDecimal((Double) obj); } if (obj.toString().matches(".*[0-9]+.*") && obj.toString().matches("[-+]?[0-9]*.[0-9]*")) { return new BigDecimal(obj.toString()); } return getNull(); } public static boolean isNull(Object obj) { return obj == NULL; } @SuppressWarnings("unchecked") public static <T> T getNull() { return (T) NULL; } }