Java BigDecimal Create getBigDecimal(final String str, final int scale)

Here you can find the source of getBigDecimal(final String str, final int scale)

Description

This method will return a BigDecimal for a given input string and specified scale.

License

Open Source License

Parameter

Parameter Description
input String : str int : scale

Return

the BigDecimal

Declaration

public static BigDecimal getBigDecimal(final String str, final int scale) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.math.BigDecimal;
import java.math.RoundingMode;

public class Main {
    /**//  w  w  w . ja v a  2s.  co m
     * This method will return a BigDecimal for a given input string and
     * specified scale.
     * 
     * @param input
     *            String : str int : scale
     * @return the BigDecimal
     */
    public static BigDecimal getBigDecimal(final String str, final int scale) {
        BigDecimal returnValue;
        try {
            returnValue = new BigDecimal(str).setScale(scale, RoundingMode.HALF_UP);
        } catch (Exception exception) {
            returnValue = new BigDecimal("0.00");
        }
        return returnValue;
    }
}

Related

  1. createBigDecimal(Object value)
  2. createBigDecimal(String val)
  3. getBdIgnoreNull(BigDecimal bigDecimalPara)
  4. getBigDecimal(BigDecimal bigDecimal)
  5. getBigDecimal(double value, int decimals)
  6. getBigDecimal(JsonObject object, String memberName)
  7. getBigDecimal(Map map, String attr)
  8. getBigDecimal(Number number)
  9. getBigDecimal(Object number)