Internationalization and localization tools


Locale-Sensitive Java Method

public static final NumberFormat getIntegerInstance()

public static NumberFormat getIntegerInstance(Locale inLocale)

Internationalization (I18n) Method Overview

NumberFormat is the abstract base class for all number formats. This class provides the interface for formatting and parsing numbers for any locale. Your code can be completely independent of the locale conventions for decimal points, thousands-separators, or even the particular decimal digits used, or whether the number format is even decimal.

The zero-argument factory method returns an integer number format for the default system locale. The returned number format is configured to round floating point numbers to the nearest integer using IEEE half-even rounding for formatting, and to parse only the integer part of an input string.

I18n Issues

Because the system's locale may not be the correct locale for all users, it is good I18n practice to use the factory method that accepts a Locale argument and to further pass in a Locale object that has been dynamically generated based upon the user's preferences.

Globalyzer will detect this method and report it as an I18n issue regardless of the signature used and regardless of whether it is being used correctly. If Locale is already being passed as an argument, Globalyzer will detect it to force developers to double check that the correct Locale is being passed. If you have determined that the call is being handled correctly, you can use Globalyzer's Ignore Comment functionality to ensure that it isn't picked up in a subsequent scan.

Suggested Replacement

public static NumberFormat getIntegerInstance(Locale inLocale)

Instead of:

NumberFormat formatter =
   NumberFormat.getIntegerInstance();

Use:

//Retrieve the user's locale
Locale locale = getUserLocale();
NumberFormat formatter =
   NumberFormat.getIntegerInstance(locale);

Please see Numbers for more information.

Locale-Sensitive Java Methods

 

Lingoport internationalization and localization services and software