svn commit: r1826679 - /ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/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: r1826679 - /ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilFormatOut.java

mbrohl
Author: mbrohl
Date: Tue Mar 13 20:16:12 2018
New Revision: 1826679

URL: http://svn.apache.org/viewvc?rev=1826679&view=rev
Log:
Improved: Extended UtilFormatOut with new method formatPercentageRate.
(OFBIZ-10199)

Thanks Martin for reporting and providing the patch.

Modified:
    ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilFormatOut.java

Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilFormatOut.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilFormatOut.java?rev=1826679&r1=1826678&r2=1826679&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilFormatOut.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilFormatOut.java Tue Mar 13 20:16:12 2018
@@ -210,6 +210,18 @@ public final class UtilFormatOut {
         return percentageDecimalFormat.format(percentage);
     }
 
+    /** Formats a BigDecimal value 1:1 into a percentage string (e.g. 10 to 10% instead of 0,1 to 10%)
+     * @param percentage The percentage Decimal to be formatted
+     * @return A String with the formatted percentage
+     */
+    public static String formatPercentageRate(BigDecimal percentage, boolean negate) {
+        if (percentage == null) return "";
+        if (negate) {
+            return percentageDecimalFormat.format(percentage.divide(BigDecimal.valueOf(-100)));
+        }
+        return percentageDecimalFormat.format(percentage.divide(BigDecimal.valueOf(100)));
+    }
+
     /** Formats an Long representing a quantity into a string
      * @param quantity The quantity Long to be formatted
      * @return A String with the formatted quantity