class BigDecimalUtil {

  public static BigDecimal parseFromNumberString(@Nullable String numberString) {
    BigDecimal result = null;

    if (numberString != null) {
      String nonSpacedString = numberString.replaceAll("[ \\t\\n\\x0B\\f\\r%]", "");

      if (!Strings.isNullOrEmpty(nonSpacedString)){
        int indexOfComma = nonSpacedString.indexOf(',');
        int indexOfDot = nonSpacedString.indexOf('.');
  
        DecimalFormat decimalFormat = (DecimalFormat) NumberFormat.getInstance();
        DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols();
  
        if (indexOfComma < indexOfDot) {
          otherSymbols.setDecimalSeparator('.');
          otherSymbols.setGroupingSeparator(',');
        } else {
          otherSymbols.setDecimalSeparator(',');
          otherSymbols.setGroupingSeparator('.');
        }
  
        decimalFormat.setParseBigDecimal(true);
        decimalFormat.setDecimalFormatSymbols(otherSymbols);
  
        try {
          result = (BigDecimal) decimalFormat.parse(nonSpacedString);
        } catch (ParseException e) {
          throw new RuntimeException("Error parsing '" + nonSpacedString + "' as BigDecimal", e);
        }
      }
    }
    return result;
  }

  private  BigDecimalUtil();

}