Globalization Step-by-StepOverview and DescriptionWhen dealing with numeric values, there are six major items to pay attention to:
The user can define preferred number-formatting parameters by making selections from the Numbers tab of the Customize Regional Options property sheet, within the Regional And Language Options property sheet. (See Figure 1 below.)
Figure 1: Selecting the preferred number formatting. Number Formatting in Win32The easiest way to format numbers in a way that's locale-aware is to use the GetNumberFormat API. This API customizes the format of a number string for a specified locale. The following shows how the GetNumberFormat API is used to format a given number string for the current user locale (using the default settings for number formatting that the user has defined): GetNumberFormat(LOCALE_USER_DEFAULT, // locale (current user locale) For more advanced number formatting in the Win32 programming model, the GetLocaleInfo API can be used to retrieve most of the number-formatting parameters (such as thousands separators, decimal separators, and negative numbers). Here are the appropriate flags to use as LCType in your calls to GetLocaleInfo, in order to retrieve each one of the number-formatting parameters.
Possible return values are shown in Table 2 below.
Native digits.LCType flag set to LOCALE_SNATIVEDIGITS. Here is a code sample that deals with native digits: GetLocaleInfo(LOCALE_USER_DEFAULT, // LCID (current user locale) This code would produce the following result on English (US) and Farsi locales, respectively:
Figure 2: Native digits for English (US) and Farsi.
Digit Substitution. Digit substitution defines which set of digits (with its associated shapes) should be used for presenting numbers. This information can be retrieved with the LCType flag set to LOCALE_IDIGITSUBSTITUTION. The table below shows the possible return values:
Table 3: Return values of LOCALE_IDIGITSUBSTITUTION
Number Formatting in Web PagesEarlier in Use Locale Model, you saw how to retrieve the current browser locale on the client side and how to set the global locale of your context or session to this value. Once the appropriate locale has been set, you can easily format numbers by using FormatNumber, a locale-aware function. With this function, formatting 123456.789 would become:
Obviously the scripting technology does not offer the same flexibility to manipulate number formatting as NLS APIs do in the case of Win32 programming. However, the FormatNumber function enables you to display numbers according to the cultural format that the user prefers. Number Formatting in .NET FrameworkThe NumberFormatInfo class defines how currency, decimal separators, and other numeric symbols are formatted and displayed based on culture. For example, the decimal number 10000.50 is formatted as 10,000.50 for the culture "en-US" and 10.000,50 for the culture "de-DE." An instance of NumberFormatInfo can be created for a specific cultureor the invariant culture, but not for a neutral culture. A neutral culture does not provide enough information to display the correct numeric format. Table 4-10 lists the standard format characters for each standard formatting pattern and the associated NumberFormatInfo property that can be set to modify this pattern.
Table 4: Standard format characters for basic formatting patterns and the associated NumberFormatInfo property used to modify these patterns.
The following code example displays an integer using the NumberFormatInfo standard currency format ("c") for the specified CurrentCulture.
This code produces the following output:
As when dealing with numbers, formatting conventions for addresses vary widely from one country to another. There are also discrepancies in the actual terms used when representing addresses that you will need to handle. ReferencesSee MSDN documentation for the following APIs:
|