Next | Prev | Up | Top | Contents | Index

Specifying Numbers and Money

Format of simple numbers differs from locale to locale. Characters used for decimal radix and group separators vary. Grouping rules may also vary. Even though we assume that decimal numbers are universal, there are some eighteen varying aspects of numeric formatting defined by a locale. Many of these are details of monetary formatting.

For example, Germany uses a comma to denote a decimal radix and a period to denote a group separator. English reverses these. India groups digits by two except for the last three digits before the decimal radix. Many locales have particular formats used for money, some of which are shown in Table 6-3.

Some Monetary Formats
CountryPositive FormatNegative Format
IndiaRs1,02,34,567.89Rs(1,02,34,567.89)
ItalyL.10.234.567-L.10.234.567
Japan10,234,567-10,234,567
NetherlandsF10.234.567,89F-10.234.567,89
NorwayKr10.234.567,89Kr10.234.567,89-
SwitzerlandSFr10,234,567.89SFr10,234,567.89C


Using printf()

printf() function, detailed in the printf(3S) reference page, examines LC_NUMERIC and chooses the appropriate decimal radix. If none is available, it tries to use ASCII period. No further locale-specific formatting is done directly by printf(). However, see "Variably Ordered Referencing of printf() Arguments," for a way to handle locale-specific ordering of syntactic elements in messages.


Using localeconv()

The localeconv() function, detailed in the localeconv(3C) reference page, can be called to find out about numeric formatting data, including the decimal radix (inappropriately called decimal_point), the grouping separator (inappropriately called thousands_sep), the grouping rules, and a great deal of monetary formatting information.

The localeconv() function leaves actual use of formatting information other than the decimal radix to the application.


Using strfmon()

The strfmon() function, detailed in the strfmon(3S) reference page, is new with IRIX version 6.2. Like sprintf(), strfmon() takes an output area, a format string that contains conversion specifications, and one or more argument values to be converted. It creates an output string containing fixed data and converted values.

Only two conversion types are supported: %i to convert a double value to international currency representation, and %n to convert a double value to national currency representation. You can use strfmon() to format currency values as strings, and then use printf() or other functions to write the formatted strings.


Next | Prev | Up | Top | Contents | Index