manpagez: man pages & more
man strfmon(3)
Home | html | info | man
strfmon(3)               BSD Library Functions Manual               strfmon(3)


     strfmon, strfmon_l -- convert monetary value to string


     #include <monetary.h>

     strfmon(char *restrict s, size_t maxsize, const char *restrict format,

     #include <monetary.h>
     #include <xlocale.h>

     strfmon_l(char *restrict s, size_t maxsize, locale_t loc,
         const char *restrict format, ...);


     The strfmon() function places characters into the array pointed to by s,
     as controlled by the string pointed to by format.  No more than maxsize
     bytes are placed into the array.

     While the strfmon() function uses the current locale, the strfmon_l()
     function may be passed a locale directly. See xlocale(3) for more infor-

     The format string is composed of zero or more directives: ordinary char-
     acters (not %), which are copied unchanged to the output stream; and con-
     version specifications, each of which results in fetching zero or more
     subsequent arguments.  Each conversion specification is introduced by the
     % character.  After the %, the following appear in sequence:

     o   Zero or more of the following flags:

         =f   A `=' character followed by another character f which is used as
              the numeric fill character.

         ^    Do not use grouping characters, regardless of the current locale

         +    Represent positive values by prefixing them with a positive
              sign, and negative values by prefixing them with a negative
              sign.  This is the default.

         (    Enclose negative values in parentheses.

         !    Do not include a currency symbol in the output.

         -    Left justify the result.  Only valid when a field width is spec-

     o   An optional minimum field width as a decimal number.  By default,
         there is no minimum width.

     o   A `#' sign followed by a decimal number specifying the maximum
         expected number of digits after the radix character.

     o   A `.' character followed by a decimal number specifying the number of
         digits after the radix character.

     o   One of the following conversion specifiers:

         i    The double argument is formatted as an international monetary

         n    The double argument is formatted as a national monetary amount.

         %    A `%' character is written.


     If the total number of resulting bytes, including the terminating NULL
     byte, is not more than maxsize, strfmon() 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 indeter-
     minate, and errno is set to indicate the error.


     The strfmon() function will fail if:

     [E2BIG]            Conversion stopped due to lack of space in the buffer.

     [EINVAL]           The format string is invalid.

     [ENOMEM]           Not enough memory for temporary buffers.


             #include <stdio.h>
             #include <monetary.h>
             #include <locale.h>

             int main() {
                     char buf[200];
                     setlocale(LC_ALL, "en_US");
                     (void)strfmon (buf, sizeof(buf)-1, "%n" , 123456.78);
                     printf("%s0, buf);


     localeconv(3), xlocale(3)


     The strfmon() function conforms to IEEE Std 1003.1-2001 (``POSIX.1'').


     The strfmon() function was implemented by Alexey Zelkin

     This manual page was written by Jeroen Ruigrok van der Werven
     <> based on the standard's text.


     The strfmon() function does not correctly handle multibyte characters in
     the format argument.

BSD                            October 12, 2002                            BSD

Mac OS X 10.8 - Generated Fri Aug 31 05:49:03 CDT 2012
© 2000-2024
Individual documents may contain additional copyright information.