/** * Method to format an amount using a custom rule set. * Current rule sets available: * * en_US * %dollars-and-cents - 1,225.25 becomes "one thousand two hundred twenty five dollars and twenty five cents" (useful for checks) * %dollars-and-hundreths - 1,225.25 becomes "one thousand two hundred twenty five and 25/00" (alternate for checks) * * @param amount - the amount to format * @param ruleSet - ruleSet to use * @param rule - the name of the rule set to use (e.g., %dollars-and-hundredths) * @param locale - the Locale * @return formatted string or an empty string if there was an error */ public static String formatRuleBasedAmount(double amount, String ruleSet, String rule, Locale locale) { RuleBasedNumberFormat formatter = new RuleBasedNumberFormat(ruleSet, locale); String result = ""; try { result = formatter.format(amount, rule != null ? rule : formatter.getDefaultRuleSetName()); } catch (Exception e) { Debug.logError(e, "Failed to format amount " + amount + " using rule " + rule, module); } return result; }