Java Number Format Pattern getBigDecimalFromString(String numericValue, String numberFormat)

Here you can find the source of getBigDecimalFromString(String numericValue, String numberFormat)

Description

get Big Decimal From String

License

Apache License

Declaration

public static BigDecimal getBigDecimalFromString(String numericValue,
            String numberFormat) throws ParseException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.ParseException;

public class Main {
    public static BigDecimal getBigDecimalFromString(String numericValue,
            String numberFormat) throws ParseException {

        DecimalFormatSymbols symbols = new DecimalFormatSymbols();
        symbols.setGroupingSeparator(numberFormat.charAt(0));
        symbols.setDecimalSeparator(numberFormat.charAt(1));

        DecimalFormat formatter = new DecimalFormat();
        formatter.setDecimalFormatSymbols(symbols);
        formatter.setGroupingSize(3);//from w w w.j a va 2  s .  co m
        formatter.setMinimumIntegerDigits(1);
        formatter.setMaximumIntegerDigits(Integer.MAX_VALUE);

        return new BigDecimal(formatter.parse(numericValue).toString());
    }
}

Related

  1. formatTime(long endTime, long startTime)
  2. formatTokens(long tokens)
  3. formatValue(int value)
  4. formatValue(Object value)
  5. formatWith6Digits(String input)
  6. getDataFormat(final boolean grouped, final boolean isFloat, int declen)
  7. getDefaultDecimalFormat()
  8. getExponentialFormat(int precision)
  9. getF(String tStr, String formate)