STRFMON(3POSIX)
πΈ STRFMON β the manual page, but make it cute
okay so bestie, this is STRFMON(3POSIX), straight out of the POSIX Programmer's Manual, and we're gonna get you fluent in turning money numbers into pretty strings. β¨
π¨ PROLOG (read this first, fr fr)
This manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (consult the corresponding Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux.
ngl that's the whole prolog. it's giving "we warned you." π
π NAME
strfmon, strfmon_l β convert monetary value to a string
β¨ SYNOPSIS
#include <monetary.h>
ssize_t strfmon(char *restrict s, size_t maxsize,
const char *restrict format, ...);
ssize_t strfmon_l(char *restrict s, size_t maxsize,
locale_t locale, const char *restrict format, ...);
π DESCRIPTION
So like, strfmon() drops characters into the array pointed to by s, and it's all controlled by the string pointed to by format. And bestie, listen β no more than maxsize bytes get placed into that array. Respect the limit. π«Ά
The format is a character string that begins and ends in its initial state (if any), and it's got two types of objects in it:
- plain characters β literally just copied to the output stream, no thoughts, head empty π¦
- conversion specifications β each one fetches zero or more arguments, converts them, formats them
The results are undefined if there aren't enough arguments for the format. And if the format runs out while arguments are still hanging around? Those excess arguments are simply ignored. iconic behavior tbh. π
The application shall ensure that a conversion specification consists of the following sequence:
- A
'%'character - Optional flags
- Optional field width
- Optional left precision
- Optional right precision
- A required conversion specifier character that determines the conversion to be performed
and strfmon_l()? It's the exact same as strfmon(), except the locale data used comes from the locale represented by locale. Periodt.
π Flags
One or more of these optional flags can be specified to control the conversion:
=fβ An'='followed by a single characterfused as the numeric fill character. In order to work with precision or width counts, the fill character shall be a single byte character; if not, the behavior is undefined. π The default numeric fill character is the<space>. This flag does not affect field width filling, which always uses the<space>. And heads up: this flag is ignored unless a left precision (see below) is specified.^β Do not format the currency amount with grouping characters. The default is to insert the grouping characters if they're defined for the current locale.+or(β Specify the style of representing positive and negative currency amounts. Only one of'+'or'('may be specified. If'+'is specified, the locale's equivalent of'+'and'-'are used (for example, in many locales, the empty string if positive and'-'if negative). If'('is specified, negative amounts are enclosed within parentheses. If neither flag is specified, the'+'style is used.!β Suppress the currency symbol from the output conversion. bye girl π-β Specify the alignment. If this flag is present the result of the conversion is left-justified (padded to the right) rather than right-justified. This flag shall be ignored unless a field width (see below) is specified.
π Field Width
wβ A decimal digit stringwspecifying a minimum field width in bytes in which the result of the conversion is right-justified (or left-justified if the flag'-'is specified). The default is0.
π Left Precision
#nβ A'#'followed by a decimal digit stringnspecifying a maximum number of digits expected to be formatted to the left of the radix character. This option can be used to keep the formatted output from multiple calls to thestrfmon()function aligned in the same columns. It can also be used to fill unused positions with a special character as in"$***123.45". This option causes an amount to be formatted as if it has the number of digits specified byn. If more thanndigit positions are required, this conversion specification is ignored. Digit positions in excess of those actually required are filled with the numeric fill character (see the=fflag above).
If grouping has not been suppressed with the '^' flag, and it is defined for the current locale, grouping separators are inserted before the fill characters (if any) are added. Grouping separators are not applied to fill characters even if the fill character is a digit.
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 stringpspecifying the number of digits after the radix character. If the value of the right precisionpis0, no radix character appears. If a right precision is not included, a default specified by the current locale is used. The amount being formatted is rounded to the specified number of digits prior to formatting.
β Conversion Specifier Characters
The conversion specifier characters and their meanings are:
iβ Thedoubleargument is formatted according to the locale's international currency format (for example, in the US:USD 1,234.56). If the argument isΒ±InforNaN, the result of the conversion is unspecified. πnβ Thedoubleargument is formatted according to the locale's national currency format (for example, in the US:$1,234.56). If the argument isΒ±InforNaN, the result of the conversion is unspecified. π%β Convert to a'%'; no argument is converted. The entire conversion specification shall be%%.
π Locale Information
The LC_MONETARY category of the current 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. The international currency symbol should be conformant with the ISO 4217:2001 standard.
If the value of maxsize is greater than {SSIZE_MAX}, the result is implementation-defined.
The behavior is undefined if thelocaleargument tostrfmon_l()is the special locale objectLC_GLOBAL_LOCALEor is not a valid locale object handle. Do not do this. seriously bestie, don't. π
π₯ RETURN VALUE
If the total number of resulting bytes including the terminating null byte is not more than maxsize, these functions shall return the number of bytes placed into the array pointed to by s, not including the terminating NUL character. π
Otherwise, -1 shall be returned, the contents of the array are unspecified, and errno shall be set to indicate the error. π
π ERRORS
These functions shall fail if:
E2BIGβ Conversion stopped due to lack of space in the buffer.
The following sections are informative.
π EXAMPLES
Given a locale for the US and the values 123.45, -123.45, and 3456.781, the following output might be produced. Square brackets ("[]") are used in this example to delimit the output.
%n [$123.45] Default formatting
[-$123.45]
[$3,456.78]
%11n [ $123.45] Right align within an 11-character field
[ -$123.45]
[ $3,456.78]
%#5n [ $ 123.45] Aligned columns for values up to 99999
[-$ 123.45]
[ $ 3,456.78]
%=*#5n [ $***123.45] Specify a fill character
[-$***123.45]
[ $*3,456.78]
%=0#5n [ $000123.45] Fill characters do not use grouping
[-$000123.45] even if the fill character is a digit
[ $03,456.78]
%^#5n [ $ 123.45] Disable the grouping separator
[-$ 123.45]
[ $ 3456.78]
%^#5.0n [ $ 123] Round off to whole units
[-$ 123]
[ $ 3457]
%^#5.4n [ $ 123.4500] Increase the precision
[-$ 123.4500]
[ $ 3456.7810]
%(#5n [ $ 123.45 ] Use an alternative pos/neg style
[($ 123.45)]
[ $ 3,456.78 ]
%!(#5n [ 123.45 ] Disable the currency symbol
[( 123.45)]
[ 3,456.78 ]
%-14#5.4n [ $ 123.4500 ] Left-justify the output
[-$ 123.4500 ]
[ $ 3,456.7810 ]
%14#5.4n [ $ 123.4500] Corresponding right-justified output
[ -$ 123.4500]
[ $ 3,456.7810]
See also the EXAMPLES section in fprintf().
π¦ APPLICATION USAGE
None.
π RATIONALE
None.
π FUTURE DIRECTIONS
Lowercase conversion characters are reserved for future standards use and uppercase for implementation-defined use.
π SEE ALSO
fprintf(), localeconv()
The Base Definitions volume of POSIX.1β2017, <monetary.h>
π COPYRIGHT
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
and that's the whole page, bestie β brought to you by IEEE/The Open Group, 2017, STRFMON(3POSIX) π go format some money and slay β¨π
π¦ where this page comes from
- debian bookworm: manpages-posix-dev 2017a-2 Β· Other
- debian trixie: manpages-posix-dev 2017a-2 Β· Other
- ubuntu jammy: manpages-posix-dev 2017a-2 Β· Other
- ubuntu noble: manpages-posix-dev 2017a-2 Β· Other
- ubuntu resolute: manpages-posix-dev 2017a-2build1 Β· Other
- ubuntu stonking: manpages-posix-dev 2017a-2.1 Β· Other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms