EN · DE · RU · FR · ES

#625: CurrencyFormatter.java

projectforge-business/src/main/java/org/projectforge/business/utils/CurrencyFormatter.java Java class, projectforge-business/src/main/java/org/projectforge/business/utils/CurrencyFormatter.java 93 lines · 34 code · 52 comments · 7 blank
Purpose: Source file: projectforge/business/utils/CurrencyFormatter.java. CurrencyFormatter.java is part of the ProjectForge open-source project management application.

Source (first 100 lines)

/////////////////////////////////////////////////////////////////////////////
//
// Project ProjectForge Community Edition
//         www.projectforge.org
//
// Copyright (C) 2001-2026 Micromata GmbH, Germany (www.micromata.com)
//
// ProjectForge is dual-licensed.
//
// This community edition is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as published
// by the Free Software Foundation; version 3 of the License.
//
// This community edition is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
// Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, see http://www.gnu.org/licenses/.
//
/////////////////////////////////////////////////////////////////////////////

package org.projectforge.business.utils;

import org.projectforge.business.configuration.ConfigurationServiceAccessor;
import org.projectforge.framework.persistence.user.api.ThreadLocalUserContext;
import org.projectforge.framework.utils.NumberHelper;

import java.math.BigDecimal;
import java.text.NumberFormat;
import java.util.Locale;

/**
 * Converts BigDecimal values to formatted currency strings.
 * @author Kai Reinhard (k.reinhard@micromata.de)
 *
 */
public class CurrencyFormatter
{
  /**
   * Uses the locale of the context user.
   * @param value
   * @return 1,234.00 €
   * @see #format(BigDecimal, Locale)
   */
  public static String format(final BigDecimal value)
  {
    return format(value, ThreadLocalUserContext.getLocale(), true);
  }

  /**
   * Uses the locale of the context user.
   * @param value
   * @param withCurrencySymbol If true, appends currency symbol (default true for backward compatibility)
   * @return 1,234.00 € or 1,234.00 (without symbol)
   */
  public static String format(final BigDecimal value, final boolean withCurrencySymbol)
  {
    return format(value, ThreadLocalUserContext.getLocale(), withCurrencySymbol);
  }

  /**
   * Uses the currency symbol of ConfigXml.
   * @param value
   * @param locale
   * @return 1,234.00 €
   */
  public static String format(final BigDecimal value, final Locale locale)
  {
    return format(value, locale, true);
  }

  /**
   * Uses the currency symbol of ConfigXml.
   * @param value
   * @param locale
   * @param withCurrencySymbol If true, appends currency symbol (default true for backward compatibility)
   * @return 1,234.00 € or 1,234.00 (without symbol)
   */
  public static String format(final BigDecimal value, final Locale locale, final boolean withCurrencySymbol)
  {
    if (value == null) {
      return "";
    }
    NumberFormat nf = NumberHelper.getCurrencyFormat(locale);
    if (withCurrencySymbol) {
      return nf.format(value) + " " + ConfigurationServiceAccessor.get().getCurrencySymbol();
    } else {
      return nf.format(value);
    }
  }
}

Git History

868d6abb7 2025 -> 2026
11122c04f  Add optional withCurrencySymbol parameter to CurrencyFormatter and CurrencyConverter (default true for backward compatibility). Update invoice forms to display amounts without  currency symbols.
63081666f Source file headers: 2024-> 2025.
b6092df09 Copyright 2023 -> 2024
ab45d51fa Copyright 2001-2022 -> 2001-2023.

868d6abb7

2025 -> 2026
868d6abb75cd191a892911ac8e45058932cf9074
diff --git a/projectforge-business/src/main/java/org/projectforge/business/utils/CurrencyFormatter.java b/projectforge-business/src/main/java/org/projectforge/business/utils/CurrencyFormatter.java
index 97e3b3a72..de7e8ad41 100644
--- a/projectforge-business/src/main/java/org/projectforge/business/utils/CurrencyFormatter.java
+++ b/projectforge-business/src/main/java/org/projectforge/business/utils/CurrencyFormatter.java
@@ -3,7 +3,7 @@
 // Project ProjectForge Community Edition
 //         www.projectforge.org
 //
-// Copyright (C) 2001-2025 Micromata GmbH, Germany (www.micromata.com)
+// Copyright (C) 2001-2026 Micromata GmbH, Germany (www.micromata.com)
 //
 // ProjectForge is dual-licensed.
 //

11122c04f

Add optional withCurrencySymbol parameter to CurrencyFormatter and CurrencyConverter (default true for backward compatibility). Update invoice forms to display amounts without currency symbols.
11122c04f5a35f05f1f116382357407b9e16452c
diff --git a/projectforge-business/src/main/java/org/projectforge/business/utils/CurrencyFormatter.java b/projectforge-business/src/main/java/org/projectforge/business/utils/CurrencyFormatter.java
index 86d69ceb9..97e3b3a72 100644
--- a/projectforge-business/src/main/java/org/projectforge/business/utils/CurrencyFormatter.java
+++ b/projectforge-business/src/main/java/org/projectforge/business/utils/CurrencyFormatter.java
@@ -46,7 +46,18 @@ public class CurrencyFormatter
    */
   public static String format(final BigDecimal value)
   {
-    return format(value, ThreadLocalUserContext.getLocale());
+    return format(value, ThreadLocalUserContext.getLocale(), true);
+  }
+
+  /**
+   * Uses the locale of the context user.
+   * @param value
+   * @param withCurrencySymbol If true, appends currency symbol (default true for backward compatibility)
+   * @return 1,234.00 € or 1,234.00 (without symbol)
+   */
+  public static String format(final BigDecimal value, final boolean withCurrencySymbol)
+  {
+    return format(value, ThreadLocalUserContext.getLocale(), withCurrencySymbol);
   }
 
   /**
@@ -56,11 +67,27 @@ public class CurrencyFormatter
    * @return 1,234.00 €
    */
   public static String format(final BigDecimal value, final Locale locale)
+  {
+    return format(value, locale, true);
+  }
+
+  /**
+   * Uses the currency symbol of ConfigXml.
+   * @param value
+   * @param locale
+   * @param withCurrencySymbol If true, appends currency symbol (default true for backward compatibility)
+   * @return 1,234.00 € or 1,234.00 (without symbol)
+   */
+  public static String format(final BigDecimal value, final Locale locale, final boolean withCurrencySymbol)
   {
     if (value == null) {
       return "";
     }
     NumberFormat nf = NumberHelper.getCurrencyFormat(locale);
-    return nf.format(value) + " " + ConfigurationServiceAccessor.get().getCurrencySymbol();
+    if (withCurrencySymbol) {
+      return nf.format(value) + " " + ConfigurationServiceAccessor.get().getCurrencySymbol();
+    } else {
+      return nf.format(value);
+    }
   }
 }

63081666f

Source file headers: 2024-> 2025.
63081666f620fb87315f01b817e560e0b2f6a33a
diff --git a/projectforge-business/src/main/java/org/projectforge/business/utils/CurrencyFormatter.java b/projectforge-business/src/main/java/org/projectforge/business/utils/CurrencyFormatter.java
index 729aec945..86d69ceb9 100644
--- a/projectforge-business/src/main/java/org/projectforge/business/utils/CurrencyFormatter.java
+++ b/projectforge-business/src/main/java/org/projectforge/business/utils/CurrencyFormatter.java
@@ -3,7 +3,7 @@
 // Project ProjectForge Community Edition
 //         www.projectforge.org
 //
-// Copyright (C) 2001-2024 Micromata GmbH, Germany (www.micromata.com)
+// Copyright (C) 2001-2025 Micromata GmbH, Germany (www.micromata.com)
 //
 // ProjectForge is dual-licensed.
 //

b6092df09

Copyright 2023 -> 2024
b6092df0927c4a3b161e888445f31dcab57493f2
diff --git a/projectforge-business/src/main/java/org/projectforge/business/utils/CurrencyFormatter.java b/projectforge-business/src/main/java/org/projectforge/business/utils/CurrencyFormatter.java
index 7932d18fd..729aec945 100644
--- a/projectforge-business/src/main/java/org/projectforge/business/utils/CurrencyFormatter.java
+++ b/projectforge-business/src/main/java/org/projectforge/business/utils/CurrencyFormatter.java
@@ -3,7 +3,7 @@
 // Project ProjectForge Community Edition
 //         www.projectforge.org
 //
-// Copyright (C) 2001-2023 Micromata GmbH, Germany (www.micromata.com)
+// Copyright (C) 2001-2024 Micromata GmbH, Germany (www.micromata.com)
 //
 // ProjectForge is dual-licensed.
 //

ab45d51fa

Copyright 2001-2022 -> 2001-2023.
ab45d51fa419ede6174b31d69987f96d4b841ff9
diff --git a/projectforge-business/src/main/java/org/projectforge/business/utils/CurrencyFormatter.java b/projectforge-business/src/main/java/org/projectforge/business/utils/CurrencyFormatter.java
index 4d7b3a7f3..7932d18fd 100644
--- a/projectforge-business/src/main/java/org/projectforge/business/utils/CurrencyFormatter.java
+++ b/projectforge-business/src/main/java/org/projectforge/business/utils/CurrencyFormatter.java
@@ -3,7 +3,7 @@
 // Project ProjectForge Community Edition
 //         www.projectforge.org
 //
-// Copyright (C) 2001-2022 Micromata GmbH, Germany (www.micromata.com)
+// Copyright (C) 2001-2023 Micromata GmbH, Germany (www.micromata.com)
 //
 // ProjectForge is dual-licensed.
 //