/** * Parse the given {@link String} as float. * * @param sStr * The string to parse. May be <code>null</code>. * @param fDefault * The default value to be returned if the passed object could not be * converted to a valid value. * @return The default value if the string does not represent a valid value. */ public static float parseFloat (@Nullable final String sStr, final float fDefault) { // parseDouble throws a NPE if parameter is null if (sStr != null && sStr.length () > 0) try { // Single point where we replace "," with "." for parsing! return Float.parseFloat (_getUnifiedDecimal (sStr)); } catch (final NumberFormatException ex)// NOPMD { // Fall through } return fDefault; }
/** * Parse the given {@link String} as double. * * @param sStr * The string to parse. May be <code>null</code>. * @param dDefault * The default value to be returned if the passed object could not be * converted to a valid value. * @return The default value if the string does not represent a valid value. */ public static double parseDouble (@Nullable final String sStr, final double dDefault) { // parseDouble throws a NPE if parameter is null if (sStr != null && sStr.length () > 0) try { // Single point where we replace "," with "." for parsing! return Double.parseDouble (_getUnifiedDecimal (sStr)); } catch (final NumberFormatException ex)// NOPMD { // Fall through } return dDefault; }
/** * Parse the given {@link String} as {@link BigDecimal}. * * @param sStr * The String to parse. May be <code>null</code>. * @param aDefault * The default value to be returned if the passed string could not be * converted to a valid value. May be <code>null</code>. * @return <code>aDefault</code> if the string does not represent a valid * value. */ @Nullable public static BigDecimal parseBigDecimal (@Nullable final String sStr, @Nullable final BigDecimal aDefault) { if (sStr != null && sStr.length () > 0) try { return new BigDecimal (_getUnifiedDecimal (sStr)); } catch (final NumberFormatException ex)// NOPMD { // Fall through } return aDefault; }
try return new BigDecimal (_getUnifiedDecimal (sStr)).setScale (nScale, eRoundingMode);