svn commit: r463137 - /incubator/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilFormatOut.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r463137 - /incubator/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilFormatOut.java

jacopoc
Author: jacopoc
Date: Wed Oct 11 23:04:33 2006
New Revision: 463137

URL: http://svn.apache.org/viewvc?view=rev&rev=463137
Log:
Added new currencyFormat method that accepts as input the maximum number of fraction digits: if the value is >= 0 then it is used to override the default value of the currency format of the given locale.

Modified:
    incubator/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilFormatOut.java

Modified: incubator/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilFormatOut.java
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilFormatOut.java?view=diff&rev=463137&r1=463136&r2=463137
==============================================================================
--- incubator/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilFormatOut.java (original)
+++ incubator/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilFormatOut.java Wed Oct 11 23:04:33 2006
@@ -69,11 +69,15 @@
      * @param price The price double to be formatted
      * @param isoCode the currency ISO code
      * @param locale The Locale used to format the number
+     * @param maximumFractionDigits The maximum number of fraction digits used; if set to -1 than the default value for the locale is used
      * @return A String with the formatted price
      */
-    public static String formatCurrency(double price, String isoCode, Locale locale) {
+    public static String formatCurrency(double price, String isoCode, Locale locale, int maximumFractionDigits) {
         //Debug.logInfo("formatting currency: " + price + ", isoCode: " + isoCode + ", locale: " + locale, module);
         com.ibm.icu.text.NumberFormat nf = com.ibm.icu.text.NumberFormat.getCurrencyInstance(locale);
+        if (maximumFractionDigits >= 0) {
+            nf.setMaximumFractionDigits(maximumFractionDigits);
+        }
         if (isoCode != null && isoCode.length() > 1) {
             nf.setCurrency(com.ibm.icu.util.Currency.getInstance(isoCode));
         } else {
@@ -83,13 +87,34 @@
     }
 
     /** Formats a double into a properly formatted currency string based on isoCode and Locale
+     * @param price The price double to be formatted
+     * @param isoCode the currency ISO code
+     * @param locale The Locale used to format the number
+     * @return A String with the formatted price
+     */
+    public static String formatCurrency(double price, String isoCode, Locale locale) {
+        return formatCurrency(price, isoCode, locale, -1);
+    }
+
+    /** Formats a double into a properly formatted currency string based on isoCode and Locale
+     * @param price The price Double to be formatted
+     * @param isoCode the currency ISO code
+     * @param locale The Locale used to format the number
+     * @param maximumFractionDigits The maximum number of fraction digits used; if set to -1 than the default value for the locale is used
+     * @return A String with the formatted price
+     */
+    public static String formatCurrency(Double price, String isoCode, Locale locale, int maximumFractionDigits) {
+        return formatCurrency(price.doubleValue(), isoCode, locale, maximumFractionDigits);
+    }
+
+    /** Formats a double into a properly formatted currency string based on isoCode and Locale
      * @param price The price Double to be formatted
      * @param isoCode the currency ISO code
      * @param locale The Locale used to format the number
      * @return A String with the formatted price
      */
     public static String formatCurrency(Double price, String isoCode, Locale locale) {
-        return formatCurrency(price.doubleValue(), isoCode, locale);
+        return formatCurrency(price.doubleValue(), isoCode, locale, -1);
     }
 
     /** Formats a Double into a properly spelled out number string based on Locale