locale snippets

Format currency by Locale in Java

Tagged currency formatting, locale, java, rahan formatointi, formattering av valuta  Languages java

There are a few ways to format currency to your own locale. If you want the formatted result to appear without the currency sign then this is probably one of the better ways to do it. In the real world you would dig the locale from the user's request or session and pass it as a parameter to the method.

public static String formatCurrency(String amount) {
    NumberFormat decimalFormat = NumberFormat.getInstance(new Locale("fi", "FI", ""));
    decimalFormat.setMinimumFractionDigits(2);
    return decimalFormat.format(amount);
}

How to Fix "bash: warning: setlocale: LC_ALL: cannot change locale (en_US)"

Tagged lc_all, setlocal, locale, debian, ubuntu  Languages 

Tested on Debian.

Edit the default locale:

sudo vim /etc/default/locale

Add the following:

LANGUAGE=en_US.UTF-8
LANG=en_US.UTF-8
LC_ALL=en_US.UTF-8

Run these commands:

sudo locale-gen en_US.UTF-8
sudo dpkg-reconfigure locales

Note if you're connecting to a server the issue might be on either your machine or the server.