Rogue Wave banner
Previous fileTop of DocumentContentsIndexNext file

9.1 Localization


NOTE: This section concentrates on locale issues in C++ code. For a discussion of these issues in Java, see the JDK documentation for java.util.locale, and its related classes.

When you start an application, the system sets a default locale that the application uses to determine what decimal points and thousands separators should look like. You can, however, change the locale at runtime. For example, you might start off using one locale where the decimal point is a period and the thousands separator is a comma, read in a set of values with embedded decimal points and commas interpreted in this way, switch to a new locale where the meanings are reversed, then print out the numbers with the new punctuation meanings.

Changes in locale are specified using the global() method of the RWLocale class of Tools.h++, as shown in lines //1 and //2. This method changes the interpretation of commas and decimal points during the input and output parsing of strings in the RWDecimal and RWDecimalPortable classes. The setLocale() method should be called only if the default locale, initialized at the start of a program, is not desired.

Note that picture objects of type RWDecimalFormat do not change their meanings when you change locales, nor is a picture object interpreted properly at construction time if the wrong locale is set. In the following example, the picture objects would not work as expected if the German picture were created while the USA locale was active:

The following example shows another way to output currency values according to different locales, using picture objects instead of changing the global locale directly:

Also note that when you initialize an RWDecimal object with a string containing embedded decimal points and commas, the punctuation marks are interpreted according to the currently active locale. For example:

If you print out numbers with embedded decimal points and commas, the punctuation marks will be interpreted according to the currently active locale, as illustrated in the first example.

For more information on what you can do with locales, see the documentation for RWLocaleSnapshot in your Tools.h++ Class Reference. For instance, this code prints out a number with the currency symbol of the currently active locale:


Previous fileTop of DocumentContentsIndexNext file

©Copyright 1999, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.