Yesterday, I introduced International Components for Unicode for Java (ICU4J) by describing how you can get rid of it. I feel pretty about about that, because ICU4J provides goodness that’s too important to simply dismiss. If you’re building applications for an international audience, you have to get this stuff right.
I spent a few minutes today browsing around for a definitive list of reasons why ICU4J is better than what is provided by the standard Java libraries. So far, I haven’t been able to find that list. What I did find is a few examples of where ICU4J shines.
Consider the following example:
NumberFormat format = NumberFormat.getCurrencyInstance();
format.setCurrency(Currency.getInstance("JPY"));
System.out.println(format.format(4.0));
With ICU4J, the output of this is “¥4”; using the standard libraries that ship with Java 6, the output is “JPY4.00”. Very different results. I’m no expert on international currencies, but a cursory review of the web shows me that the former is more common/correct (the use of the proper symbol is a dead giveaway). You can coerce the number of decimal points using the setMinimumFractionDigits() methods.