Author: arunpatidar
Date: Sat Sep 23 13:18:41 2017 New Revision: 1809425 URL: http://svn.apache.org/viewvc?rev=1809425&view=rev Log: IMPROVED: Update UtilMisc.formatRuleBasedAmount() method to take rules and ruleSet and formatting can be done, rather than system providing all ruleset support. (OFBIZ-9490) Thanks Pradhan Yash Sharma for your contribution. Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilNumber.java Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilNumber.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilNumber.java?rev=1809425&r1=1809424&r2=1809425&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilNumber.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilNumber.java Sat Sep 23 13:18:41 2017 @@ -257,25 +257,38 @@ public final class UtilNumber { * 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 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 rule, Locale locale) { + public static String formatRuleBasedAmount(double amount, Locale locale) { String ruleSet = rbnfRuleSets.get(locale); if (ruleSet == null) { Debug.logWarning("Cannot format rule based amount for locale " + locale.toString() + " because rule set for that locale does not exist", module); return ""; } + return formatRuleBasedAmount(amount, ruleSet, null, locale); + } + + /** + * 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); + result = formatter.format(amount, rule != null ? rule : formatter.getDefaultRuleSetName()); } catch (Exception e) { Debug.logError(e, "Failed to format amount " + amount + " using rule " + rule, module); } |
Free forum by Nabble | Edit this page |