Java BigDecimal Create getBigDecimalValue(Object o)

Here you can find the source of getBigDecimalValue(Object o)

Description

Converts an object to a BigDecimal using the string representation of the object.

License

Open Source License

Return

The converted BigDecimal. Returns null if the object is null or the string representation of the object is a zero length string.

Declaration

public static BigDecimal getBigDecimalValue(Object o) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2010-2015 BSI Business Systems Integration AG.
 * 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
 *
 * Contributors:// w w w.  j  a v  a  2 s.c o m
 *     BSI Business Systems Integration AG - initial API and implementation
 ******************************************************************************/

import java.math.BigDecimal;

public class Main {
    /**
     * Converts an object to a BigDecimal using the string representation of the object.
     *
     * @return The converted BigDecimal. Returns <code>null</code> if the object is <code>null</code> or the string
     *         representation of the object is a zero length string.
     */
    public static BigDecimal getBigDecimalValue(Object o) {
        if (o != null && o.toString().length() > 0) {
            return new BigDecimal(o.toString());
        } else {
            return null;
        }
    }
}

Related

  1. getBigDecimalByObject(Object obj)
  2. getBigDecimalFrom(double value)
  3. getBigDecimalFromByteArray(byte[] bytes, int start, int length, int scale)
  4. getBigDecimalFromPrimitiveTypes(int input, int scale, int precision)
  5. getBigDecimalOrNull(Object value)
  6. getDecimal(double a)
  7. getDecimal(Object[] data, int ordinal)
  8. getDecimal(String clusive, int[] currentDecimal)
  9. getDecimal(String number, BigDecimal def)