HP-UX Reference (11i v2 04/09) - 3 Library Functions N-Z (vol 7)

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 locale’s 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 %%.
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.
Section 31012 Hewlett-Packard Company 2 HP-UX 11i Version 2: September 2004