From 7bc137dd35d3f308d8bd74f5cc9223be98b8e6e9 Mon Sep 17 00:00:00 2001 From: Michael Brohl Date: Tue, 13 Mar 2018 20:16:12 +0000 Subject: [PATCH] Improved: Extended UtilFormatOut with new method formatPercentageRate. (OFBIZ-10199) Thanks Martin for reporting and providing the patch. git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1826679 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/ofbiz/base/util/UtilFormatOut.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilFormatOut.java b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilFormatOut.java index 52f966255e..37f929d0da 100644 --- a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilFormatOut.java +++ b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilFormatOut.java @@ -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