Java BigDecimal Create toBigDecimal(String bigDecimal)

Here you can find the source of toBigDecimal(String bigDecimal)

Description

Wandelt einen BigDecimal im AT Format in einen BigDecimal um

License

Open Source License

Parameter

Parameter Description
bigDecimal ist die Stringrepresentation des BigDecimal

Return

null wenn bigDecimal nicht umgewandelt werden konnte, ansonsten der BigDecimal

Declaration

public static BigDecimal toBigDecimal(String bigDecimal) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * HELIUM V, Open Source ERP software for sustained success
 * at small and medium-sized enterprises.
 * Copyright (C) 2004 - 2014 HELIUM V IT-Solutions GmbH
 * /*from   w  ww .  j  a  v  a2s.  c  om*/
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published 
 * by the Free Software Foundation, either version 3 of theLicense, or 
 * (at your option) any later version.
 * 
 * According to sec. 7 of the GNU Affero General Public License, version 3, 
 * the terms of the AGPL are supplemented with the following terms:
 * 
 * "HELIUM V" and "HELIUM 5" are registered trademarks of 
 * HELIUM V IT-Solutions GmbH. The licensing of the program under the 
 * AGPL does not imply a trademark license. Therefore any rights, title and
 * interest in our trademarks remain entirely with us. If you want to propagate
 * modified versions of the Program under the name "HELIUM V" or "HELIUM 5",
 * you may only do so if you have a written permission by HELIUM V IT-Solutions 
 * GmbH (to acquire a permission please contact HELIUM V IT-Solutions
 * at trademark@heliumv.com).
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * Contact: developers@heliumv.com
 ******************************************************************************/

import java.math.BigDecimal;

import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.ParseException;

import java.util.Locale;

public class Main {
    /**
     * Wandelt einen BigDecimal im AT Format in einen BigDecimal um
     * 
     * @param bigDecimal
     *            ist die Stringrepresentation des BigDecimal
     * @return null wenn bigDecimal nicht umgewandelt werden konnte, ansonsten
     *         der BigDecimal
     */
    public static BigDecimal toBigDecimal(String bigDecimal) {
        return toBigDecimal(bigDecimal, new Locale("de", "AT"));
    }

    /**
     * Wandelt einen BigDecimalString im angegebenen Locale in einen BigDecimal
     * um
     * 
     * @param bigDecimal
     *            die Stringrepresentation in der jeweiligen Locale
     * @param stringLocale
     *            die Locale
     * @return null wenn bigDecimal nicht in einen BigDecimal umgewandelt werden
     *         kann
     */
    public static BigDecimal toBigDecimal(String bigDecimal,
            Locale stringLocale) {
        if (null == bigDecimal)
            return null;

        BigDecimal bd = null;

        if (null == stringLocale) {
            stringLocale = new Locale("de", "AT");
        }

        try {
            DecimalFormat nf = (DecimalFormat) NumberFormat
                    .getInstance(stringLocale);
            nf.setParseBigDecimal(true);

            bd = (BigDecimal) nf.parse(bigDecimal);
            return bd;
        } catch (ParseException e) {
        }

        return null;
    }
}

Related

  1. toBig(Object o)
  2. toBigDecimal(final Object o)
  3. toBigDecimal(final Object value)
  4. toBigDecimal(Object o)
  5. toBigDecimal(Object obj)
  6. toBigDecimal(String text)
  7. toBigNumber(Number n)