strfmon.3c (2010 09)

s
strfmon(3C) strfmon(3C)
To ensure alignment, any characters appearing before or after the number in the formatted
output such as currency or sign symbols are padded as necessary with space characters to
make their positive and negative formats an equal length.
Right Precision
.p A period followed by a decimal digit string p specifying the number of digits after the radix
character If the value of the right precision p is zero, no radix character appears If a right pre-
cision is not included, a default specified by the current locale is used The amount being for-
matted is rounded to the specified number of digits prior to formatting.
Conversion Characters
The conversion characters and their meanings are:
i The double argument is formatted according to the locale’s international currency format (for
example, in the en_US.roman8 locale: USD 1,234.56).
n The double argument is formatted according to the locales national currency format (for
example, in the en_US.roman8 locale: $1,234.56).
% Convert to a %; no argument is converted. The entire conversion specification must be %%.
Notes
The behavior of the
strfmon() function in a UNIX 2003 conforming application differs from its
behavior in a non-conforming application. With the conversion character
i, the strfmon() function
uses the fourth character of the string defined in
int_curr_symbol
of the current locale instead of a
space as a separator for separating different items in a monetary quantity as dictated by the values of
int_p_sep_by_space
and int_n_sep_by_space. Only the first three characters will be taken as
the currency symbol. As a result, the formatting of internationally formatted monetary quantities may
change.
EXTERNAL INFLUENCES
Locale
The
LC_MONETARY category of the program’s locale affects the behavior of this function including the
monetary radix character (which may be different from the numeric radix character affected by the
LC_NUMERIC category), the grouping separator, the currency symbols and formats.
RETURN VALUE
If the total number of resulting bytes including the terminating null byte is not more than maxsize, the
strfmon() function returns the number of bytes placed into the array pointed to by s, not including the
terminating null byte Otherwise, 1 is returned, the contents of the array are indeterminate, and errno is
set to indicate the error.
ERRORS
The
strfmon() function will fail if:
[E2BIG] Conversion stopped due to lack of space in the buffer.
EXAMPLES
The following program segment formats the monetary value -4321.123 using the en_US.roman8
locale with a left precision of 5 and * as the fill character.
char string[31];
double amt = -4321.123;
setlocale(LC_MONETARY, "en_US.roman8");
strfmon(string, 31, "The amount is %=*#5n.", amt);
The string array will contain:
The amount is -$*4,321.12.
As an other example, given the locale of en_US.roman8 and the values 123.45, -123.45 and
3456.781:
2 Hewlett-Packard Company 2 HP-UX 11i Version 3: September 2010