@ Nullable public static BigDecimal parseCurrency ( @ Nullable final String sStr , @ Nonnull final DecimalFormat aFormat , @ Nullable final BigDecimal aDefault , @ Nonnull final RoundingMode eRoundingMode ) { // Shortcut if ( StringHelper . hasNoText ( sStr ) ) return aDefault ; // So that the call to "parse" returns a BigDecimal aFormat . setParseBigDecimal ( true ) ; aFormat . setRoundingMode ( eRoundingMode ) ; // Parse as double final BigDecimal aNum = LocaleParser . parseBigDecimal ( sStr , aFormat ) ; if ( aNum == null ) return aDefault ; // And finally do the correct scaling, depending of the decimal format // fraction return aNum . setScale ( aFormat . getMaximumFractionDigits ( ) , eRoundingMode ) ; }
Parse a currency value from string using a custom rounding mode .