/** * Safely convert a string to a Bigdecimal * * @param bigDecimalValue The String to convert. * @return Zero if the String is not a Bigdecimal. Otherwise, the Bigdecimal. */ public static BigDecimal convertStringToBigDecimal(String bigDecimalValue) { bigDecimalValue = StringUtilities.trimSafely(bigDecimalValue, "0.0"); try { return new BigDecimal(bigDecimalValue); } catch (Exception e) { return new BigDecimal(0.0); } }
/** * Safely convert a string to a long * * @param numericValue The String to convert. * @return Zero if the String is not a number. Otherwise, the long integer. */ public static long convertStringToLong(String numericValue) { long number = 0; numericValue = StringUtilities.trimSafely(numericValue, "0"); try { number = Long.parseLong(numericValue); } catch (Exception e) { number = 0; } return number; }
/** * Safely convert a string to an integer * * @param numericValue The String to convert. * @return Zero if the String is not a number. Otherwise, the integer. */ public static int convertStringToInt(String numericValue) { int number = 0; numericValue = StringUtilities.trimSafely(numericValue, "0"); try { number = Integer.parseInt(numericValue); } catch (Exception e) { number = 0; } return number; }