Here you can find the source of toBigDecimal(Object obj)
Parameter | Description |
---|---|
obj | a parameter |
public static BigDecimal toBigDecimal(Object obj)
//package com.java2s; /**/* w ww . j a v a2s . co m*/ * Copyright (c) 2010-2014, openHAB.org and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ import java.math.BigDecimal; public class Main { /** * Convert number object to BigDecimal * @param obj * @return */ public static BigDecimal toBigDecimal(Object obj) { if (obj instanceof Integer) { return BigDecimal.valueOf((int) obj); } else if (obj instanceof Long) { return BigDecimal.valueOf((long) obj); } else if (obj instanceof Short) { return BigDecimal.valueOf((short) obj); } else if (obj instanceof Double) { return BigDecimal.valueOf((double) obj); } else if (obj instanceof Float) { return BigDecimal.valueOf((float) obj); } else if (obj instanceof BigDecimal) { return (BigDecimal) obj; } return null; } }