No need to reinvent the wheel. DecimalFormat comes with currency support:

String output = DecimalFormat.getCurrencyInstance().format(123.45);

This also comes with full locale support by optionally passing in a Locale:

String output = DecimalFormat.getCurrencyInstance(Locale.GERMANY).format( 123.45);

Here's a test:

System.out.println(DecimalFormat.getCurrencyInstance().format( 123.45) );
System.out.println(DecimalFormat.getCurrencyInstance(Locale.GERMANY).format( 123.45)) ;

Output:

$123.45
123,45 €
Answer from Bohemian on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-program-to-convert-a-string-to-a-currency-format
Java Program to Convert a String to a Currency Format - GeeksforGeeks
July 23, 2025 - We have created a DecimalFormat object named formatter with the pattern "$#,##0.00", which specifies the currency format with two decimal places and commas for thousands of separators.
Top answer
1 of 2
20

Different currencies can also place the currency symbol before or after the string, or have a different number of decimal places (if any). It is not really clear from your question how you want to handle those cases, but assuming you want to preserve those differences, try this.

Instead of just swapping in the currency symbol into your local number format, you could start with the foreign format and substitute the decimal format symbols with your local version. Those also include the currency, so you have to swap that back (don't worry, it's a copy).

public static NumberFormat localStyleForeignFormat(Locale locale) {
    NumberFormat format = NumberFormat.getCurrencyInstance(locale);
    if (format instanceof DecimalFormat) {
        DecimalFormat df = (DecimalFormat) format;
        // use local/default decimal symbols with original currency symbol
        DecimalFormatSymbols dfs = new DecimalFormat().getDecimalFormatSymbols();
        dfs.setCurrency(df.getCurrency());
        df.setDecimalFormatSymbols(dfs);
    }
    return format;
}

This way, you also retain the correct positioning of the currency symbol and the number of decimal places. Some examples, for default-Locale Locale.UK

en_GB   £500,000.00     £500,000.00
fr_FR   500 000,00 €    500,000.00 €
it_IT   € 500.000,00    € 500,000.00
ja_JP   ¥500,000       JPY500,000
hi_IN   रू ५००,०००.००    INR 500,000.00

If you also want to preserve the foreign currency symbol, instead of the local equivalent, use

localDfs.setCurrencySymbol(df.getCurrency().getSymbol(locale));
2 of 2
7

You can specify the currency symbol on the NumberFormat with the setCurrency method.

Then simply use the Locale.UK to have the proper grouping separator displayed.

format.setCurrency(Currency.getInstance("EUR"));

Note that for a better handling of the grouping/decimal separator you might want to use a DecimalFormat instead.

DecimalFormatSymbols custom=new DecimalFormatSymbols();
custom.setDecimalSeparator('.');
custom.setGroupingSeparator(',');
DecimalFormat format = DecimalFormat.getInstance();
format.setDecimalFormatSymbols(custom);
format.setCurrency(Currency.getInstance("EUR"));

Then specify the correct pattern, example "€ ###,###.00".

🌐
Oracle
docs.oracle.com › javase › tutorial › i18n › format › numberFormat.html
Using Predefined Formats (The Java™ Tutorials > Internationalization > Formatting)
To implement this update and thereby supersede the default currency at runtime, create a properties file named <JAVA_HOME>/lib/currency.properties. This file contains the key/value pairs of the ISO 3166 country code, and the ISO 4217 currency data. The value part consists of three comma-separated ISO 4217 currency values: an alphabetic code, a numeric code, and a minor unit. Any lines beginning with the hash character (#), are treated as comment lines.
🌐
Oracle
docs.oracle.com › javase › tutorial › i18n › format › numberintro.html
Numbers and Currencies (The Java™ Tutorials > Internationalization > Formatting)
Using the factory methods provided by the NumberFormat class, you can get locale-specific formats for numbers, currencies, and percentages. With the DecimalFormat class you specify a number's format with a String pattern. The DecimalFormatSymbols class allows you to modify formatting symbols such as decimal separators and minus signs.
🌐
Kodejava
kodejava.org › how-do-i-change-the-currency-symbol
How do I change the currency symbol? - Learn Java by Examples
package org.kodejava.text; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.text.NumberFormat; import java.util.Locale; public class CurrencyFormatSymbols { public static void main(String[] args) { double number = 123456.789; Locale[] locales = { Locale.CANADA, Locale.GERMANY, Locale.UK, Locale.ITALY, Locale.US }; String[] symbols = {"CAD", "EUR", "GBP", "ITL", "USD"}; for (int i = 0; i < locales.length; i++) { // Gets currency's formatted value for each locale // without change the currency symbol DecimalFormat formatter = (DecimalFormat) NumberFormat.getCurrencyInstance(locales[i]); String before = formatter.format(number); // Create a DecimalFormatSymbols for each locale and sets // its new currency symbol.
🌐
Kodejava
kodejava.org › how-do-i-format-a-number-as-currency-string
How do I format a number as currency string? - Learn Java by Examples
package org.kodejava.text; import java.text.NumberFormat; import java.util.Locale; public class LocaleCurrencyFormat { public static void main(String[] args) { Double number = 1500D; // Format currency for Canada locale in Canada locale, // the decimal point symbol is a comma and currency // symbol is $. NumberFormat format = NumberFormat.getCurrencyInstance(Locale.CANADA); String currency = format.format(number); System.out.println("Currency in Canada : " + currency); // Format currency for Germany locale in German locale, // the decimal point symbol is a dot and currency symbol // is €. format = NumberFormat.getCurrencyInstance(Locale.GERMANY); currency = format.format(number); System.out.println("Currency in Germany: " + currency); } } Here is an output for the currency format using the Locale.CANADA and Locale.GERMANY.
Top answer
1 of 8
62

Try using setCurrency on the instance returned by getCurrencyInstance(Locale.GERMANY)

Broken:

java.text.NumberFormat format = java.text.NumberFormat.getCurrencyInstance(java.util.Locale.GERMANY);
System.out.println(format.format(23));

Output: 23,00 €

Fixed:

java.util.Currency usd = java.util.Currency.getInstance("USD");
java.text.NumberFormat format = java.text.NumberFormat.getCurrencyInstance(java.util.Locale.GERMANY);
format.setCurrency(usd);
System.out.println(format.format(23));

Output: 23,00 USD

2 of 8
29

I would add to answer from les2 https://stackoverflow.com/a/7828512/1536382 that I believe the number of fraction digits is not taken from the currency, it must be set manually, otherwise if client (NumberFormat) has JAPAN locale and Currency is EURO or en_US, then the amount is displayed 'a la' Yen', without fraction digits, but this is not as expected since in euro decimals are relevant, also for Japanese ;-).

So les2 example could be improved adding format.setMaximumFractionDigits(usd.getDefaultFractionDigits());, that in that particular case of the example is not relevant but it becomes relevant using a number with decimals and Locale.JAPAN as locale for NumberFormat.

    java.util.Currency usd = java.util.Currency.getInstance("USD");
    java.text.NumberFormat format = java.text.NumberFormat.getCurrencyInstance(
          java.util.Locale.JAPAN);
    format.setCurrency(usd);
    System.out.println(format.format(23.23));
    format.setMaximumFractionDigits(usd.getDefaultFractionDigits());
    System.out.println(format.format(23.23));

will output:

USD23
USD23.23

In NumberFormat code something similar is done for the initial/default currency of the format, calling method DecimalFormat#adjustForCurrencyDefaultFractionDigits. This operation is not done when the currency is changed afterwards with NumberFormat.setCurrency

Find elsewhere
🌐
Devpot
blog.termian.dev › posts › java-local-currency-symbols
How to get all currency symbols in Java
December 27, 2020 - The base classes that handle currencies are java.util.Currency and java.util.Locale. In order to display the name, symbol, and code of each available currency, our first approach to this problem could look like this: class Scratch { public static final String CURRENCY_DISPLAY_FORMAT = "Display name: %s, symbol: %s, code: %s, numericCode: %s"; private static String formatCurrency(Currency currency) { return String.format(CURRENCY_DISPLAY_FORMAT, currency.getDisplayName(), currency.getSymbol(), currency.getCurrencyCode(), currency.getNumericCodeAsString()); } public static void main(String[] args) { System.out.println("================ Currencies displayed with DISPLAY Locale ================"); System.out.println(Currency.getAvailableCurrencies() .stream() .map(Scratch::formatCurrency) .collect(Collectors.joining(System.lineSeparator())) ); } }
🌐
Coderanch
coderanch.com › t › 665504 › java › create-custom-currency-format
How to create a custom currency format [Solved] (Java in General forum at Coderanch)
I am open to taking an existing currency, such as Taiwan, and hijacking it's behavior so that it displays like '(TTT)$' instead of the normal 'NT$' formatting of Taiwan. Or, I could also as you suggest try creating a new currency/format, and using that Whatever's easiest/best, I'm fine with using.
🌐
Stack Abuse
stackabuse.com › how-to-format-number-as-currency-string-in-java
How to Format Number as Currency String in Java
January 20, 2021 - In this guide, you will use Java to format a number into a currency string. We use Locale, Currency and NumberFormat objects.
🌐
Java Code Geeks
javacodegeeks.com › home › core java
Java Currency Symbol Matching - Java Code Geeks
4 days ago - For example, a program may need to detect symbols such as $, €, £, or ₹ inside a string like "Price: ₹1200". Java provides multiple ways to handle such situations. Two common approaches are using Regular Expressions for pattern matching and using the NumberFormat class to format and interpret currency values based on locale.
🌐
Getaround Tech
getaround.tech › multi-currency-java
Multi-currency support in Java | Getaround Tech
Indeed, depending on the currency format, we have seen that the symbol can be either before the value or after the value. As we certainly don’t want to parse the format pattern, these four DecimalFormat methods will be useful: ... Now all we have to do is to draw the prefix and postfix! With the help of just a few provided APIs, we have seen that formatting a currency can be easy.
Top answer
1 of 2
5

Whenever you display a currency, you need two pieces of info: the currency code, and the locale for which you are displaying a result. For example, when you display USD in the en_US locale, you want it to show $, but in the en_AU locale, you want it to show as US$ (because Australia's currency is also called "dollars" and they use the $ symbol for AUD).

The issue you've hit is that the stock Java currency formatters stink when you are displaying a currency in its "non-primary" locale. That is, pretty much everyone in the US would rather see £ and € when showing pounds and euros, but the stock Java libraries show "GBP" and "EUR" when showing those currencies in the en_US locale.

I got around this with the following piece of code. I essentially specify my own symbols to use when displaying international currencies:

public static NumberFormat newCurrencyFormat(Currency currency, Locale displayLocale) {
    NumberFormat retVal = NumberFormat.getCurrencyInstance(displayLocale);
    retVal.setCurrency(currency);

    //The default JDK handles situations well when the currency is the default currency for the locale
    if (currency.equals(Currency.getInstance(displayLocale))) {
        return retVal;
    }

    //otherwise we need to "fix things up" when displaying a non-native currency
    if (retVal instanceof DecimalFormat) {
        DecimalFormat decimalFormat = (DecimalFormat) retVal;
        String correctedI18NSymbol = getCorrectedInternationalCurrencySymbol(currency, displayLocale);
        if (correctedI18NSymbol != null) {
            DecimalFormatSymbols dfs = decimalFormat.getDecimalFormatSymbols(); //this returns a clone of DFS
            dfs.setInternationalCurrencySymbol(correctedI18NSymbol);
            dfs.setCurrencySymbol(correctedI18NSymbol);
            decimalFormat.setDecimalFormatSymbols(dfs);
        }
    }

    return retVal;
}

private static String getCorrectedInternationalCurrencySymbol(Currency currency, Locale displayLocale) {
    ResourceBundle i18nSymbolsResourceBundle =
            ResourceBundle.getBundle("correctedI18nCurrencySymbols", displayLocale);
    if (i18nSymbolsResourceBundle.containsKey(currency.getCurrencyCode())) {
        return i18nSymbolsResourceBundle.getString(currency.getCurrencyCode());
    } else {
        return currency.getCurrencyCode();
    }
}

Then I have my properties file (correctedI18nCurrencySymbols.properties) where I specify currency symbols to use:

# Note that these are the currency symbols to use for the specified code when displaying in a DIFFERENT locale than
# the home locale of the currency. This file can be edited as needed. In addition, if in some case one specific locale
# would use a symbol DIFFERENT than the standard international one listed here, then an additional properties file
# can be added making use of the standard ResourceBundle loading algorithm. For example, if we decided we wanted to
# show US dollars as just $ instead of US$ when in the UK, we could create a file i18nCurrencySymbols_en_GB.properties
# with the entry USD=$
ARS=$AR
AUD=AU$
BOB=$b
BRL=R$
CAD=CAN$
CLP=Ch$
COP=COL$
CRC=\u20A1
HRK=kn
CZK=K\u010D
DOP=RD$
XCD=EC$
EUR=\u20AC
GTQ=Q
GYD=G$
HNL=L
HKD=HK$
HUF=Ft
INR=\u20B9
IDR=Rp
ILS=\u20AA
JMD=J$
JPY=JP\u00A5
KRW=\u20A9
NZD=NZ$
NIO=C$
PAB=B/.
PYG=Gs
PEN=S/.
PHP=\u20B1
PLN=\u007A\u0142
RON=lei
SGD=S$
ZAR=R
TWD=NT$
THB=\u0E3F
TTD=TT$
GBP=\u00A3
USD=US$
UYU=$U
VEF=Bs
VND=\u20AB
2 of 2
0

I am not familiar with Spring, but the following appears to be the issue: Locale.getDefault(). Instead, try using one of the static instances defined on the Locale class.

🌐
Avajava
avajava.com › tutorials › lessons › how-do-i-use-numberformat-to-format-currencies.html
How do I use NumberFormat to format currencies?
This is our free web tutorial index that features a variety of topics related to Java web application development.
🌐
Stevenschwenke
stevenschwenke.de › formattingCurrencyInJavaWithStringFormat
Formatting Currency in Java with string.format
void formatCurrency(BigDecimal value) { // %, => local-specific thousands separator // .2f => positions after decimal point return String.format("%,.2f", price); } @Test void formattingOfBigDecimalToString() { BigDecimal priceToFormat = BigDecimal.valueOf(23356); String formattedPrice = formatCurrency(priceToFormat); assertEquals("23.356,00", formattedPrice); priceToFormat = BigDecimal.valueOf(3245.9); formattedPrice = formatCurrency(priceToFormat); assertEquals("3.245,90", formattedPrice); priceToFormat = BigDecimal.valueOf(89645.99); formattedPrice = formatCurrency(priceToFormat); assertEqua
🌐
HackerRank
hackerrank.com › challenges › java-currency-formatter › forum
Java Currency Formatter Discussions | Java | HackerRank
import java.io.*; import java.util.*; import java.text.NumberFormat; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; public class Solution { public static void main(String[] args) { /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ Scanner scanner = new Scanner(System.in); double payment = scanner.nextDouble(); scanner.close(); NumberFormat usFormat = NumberFormat.getCurrencyInstance(Locale.US); String us = usFormat.format(payment); Locale indiaLocale = new Locale("en", "IN"); NumberFormat indiaFormat = Number
🌐
Java Code Geeks
javacodegeeks.com › home › core java
Java Currency Code Symbol Mapping Example - Java Code Geeks
May 8, 2025 - This Java class, HardcodedCurrencyMap, demonstrates how to manually map currency codes to their corresponding symbols using a hardcoded HashMap. The static map currencySymbolMap is initialized with common currency codes like USD, EUR, JPY and INR each associated with its respective symbol.