Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Currency Module User's Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

9.1 Localization


This section concentrates on locale issues in the code.

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 the Essential Tools Module, 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 is 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 the SourcePro C++ API Reference Guide. For instance, this code prints out a number with the currency symbol of the currently active locale:



Previous fileTop of DocumentContentsIndex pageNext file

Copyright © Rogue Wave Software, Inc. All Rights Reserved.

The Rogue Wave name and logo, and SourcePro, are registered trademarks of Rogue Wave Software. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.