Java BigDecimal unformattedToBigDecimal(String str)

Here you can find the source of unformattedToBigDecimal(String str)

Description

Convert an unformatted string to BigDecimal.

License

Open Source License

Parameter

Parameter Description
str The string to convert.

Return

A BigDecimal

Declaration

public static BigDecimal unformattedToBigDecimal(String str) 

Method Source Code


//package com.java2s;
/*//  w  w w  . java  2 s.c om
 * Copyright (C) 2015 Miquel Sas
 *
 * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program. If not, see
 * <http://www.gnu.org/licenses/>.
 */

import java.math.BigDecimal;

public class Main {
    /**
     * Convert an unformatted string to <code>BigDecimal</code>.
     * 
     * @return A <code>BigDecimal</code>
     * @param str The string to convert.
     */
    public static BigDecimal unformattedToBigDecimal(String str) {
        if (str == null || str.length() == 0) {
            str = "0";
        }
        BigDecimal b = new BigDecimal(str);
        return b.setScale(b.scale(), BigDecimal.ROUND_HALF_UP);
    }
}

Related

  1. transferDonateAmount2Point(BigDecimal donateAmount)
  2. tryParseBigDecimal(Object val, BigDecimal defaultVal)
  3. tryToStoreAsIntegerBigDecimal(Object ob)
  4. tryToStoreAsRealBigDecimal(Object ob)
  5. unformattedFromBigDecimal(BigDecimal n)
  6. valueOf(final BigDecimal value)
  7. writeBigDecimal(BigDecimal val, DataOutput out)
  8. writeBigDecimal(final OutputStream out, @Nullable final BigDecimal value)
  9. zeroOrMore(BigDecimal decimal)