1.\" Copyright (c) 2001 Jeroen Ruigrok van der Werven <asmodai@FreeBSD.org> 2.\" All rights reserved. 3.\" 4.\" Redistribution and use in source and binary forms, with or without 5.\" modification, are permitted provided that the following conditions 6.\" are met: 7.\" 1. Redistributions of source code must retain the above copyright 8.\" notice, this list of conditions and the following disclaimer. 9.\" 2. Redistributions in binary form must reproduce the above copyright 10.\" notice, this list of conditions and the following disclaimer in the 11.\" documentation and/or other materials provided with the distribution. 12.\" 13.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 14.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 17.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23.\" SUCH DAMAGE. 24.\" 25.\" $FreeBSD$ 26.\" 27.Dd October 26, 2022 28.Dt STRFMON 3 29.Os 30.Sh NAME 31.Nm strfmon 32.Nd convert monetary value to string 33.Sh LIBRARY 34.Lb libc 35.Sh SYNOPSIS 36.In monetary.h 37.Ft ssize_t 38.Fn strfmon "char * restrict s" "size_t maxsize" "const char * restrict format" "..." 39.Ft ssize_t 40.Fn strfmon_l "char * restrict s" "size_t maxsize" "locale_t loc" "const char * restrict format" "..." 41.Sh DESCRIPTION 42The 43.Fn strfmon 44function places characters into the array pointed to by 45.Fa s 46as controlled by the string pointed to by 47.Fa format . 48No more than 49.Fa maxsize 50bytes are placed into the array. 51.Pp 52The 53.Fn strfmon_l 54function does the same as 55.Fn strfmon 56but takes an explicit locale rather than using the current locale. 57.Pp 58The format string is composed of zero or more directives: 59ordinary characters (not 60.Cm % ) , 61which are copied unchanged to the output stream; and conversion 62specifications, each of which results in fetching zero or more subsequent 63arguments. 64Each conversion specification is introduced by the 65.Cm % 66character. 67After the 68.Cm % , 69the following appear in sequence: 70.Bl -bullet 71.It 72Zero or more of the following flags: 73.Bl -tag -width "XXX" 74.It Cm = Ns Ar f 75A 76.Sq Cm = 77character followed by another character 78.Ar f 79which is used as the numeric fill character. 80.It Cm ^ 81Do not use grouping characters, regardless of the current locale default. 82.It Cm + 83Represent positive values by prefixing them with a positive sign, 84and negative values by prefixing them with a negative sign. 85This is the default. 86.It Cm \&( 87Enclose negative values in parentheses. 88.It Cm \&! 89Do not include a currency symbol in the output. 90.It Cm \- 91Left justify the result. 92Only valid when a field width is specified. 93.El 94.It 95An optional minimum field width as a decimal number. 96By default, there is no minimum width. 97.It 98A 99.Sq Cm # 100sign followed by a decimal number specifying the maximum 101expected number of digits before the radix character. 102When this option is used, values that do not exceed the 103specified number of digits are formatted so they will be 104correctly aligned with other values printed using the same 105format. 106This includes always leaving space for a possible sign 107indicator, even if none is needed for a particular value. 108.It 109A 110.Sq Cm \&. 111character followed by a decimal number specifying the number 112of digits after the radix character. 113.It 114One of the following conversion specifiers: 115.Bl -tag -width "XXX" 116.It Cm i 117The 118.Vt double 119argument is formatted as an international monetary amount. 120.It Cm n 121The 122.Vt double 123argument is formatted as a national monetary amount. 124.It Cm % 125A 126.Sq Li % 127character is written. 128.El 129.El 130.Sh RETURN VALUES 131If the total number of resulting bytes including the terminating 132.Dv NUL 133byte is not more than 134.Fa maxsize , 135.Fn strfmon 136returns the number of bytes placed into the array pointed to by 137.Fa s , 138not including the terminating 139.Dv NUL 140byte. 141Otherwise, \-1 is returned, 142the contents of the array are indeterminate, 143and 144.Va errno 145is set to indicate the error. 146.Pp 147The 148.Fn strfmon_l 149function returns the same values as 150.Fn strfmon . 151.Sh ERRORS 152The 153.Fn strfmon 154function will fail if: 155.Bl -tag -width Er 156.It Bq Er E2BIG 157Conversion stopped due to lack of space in the buffer. 158.It Bq Er EINVAL 159The format string is invalid. 160.It Bq Er ENOMEM 161Not enough memory for temporary buffers. 162.El 163.Sh SEE ALSO 164.Xr localeconv 3 165.Sh STANDARDS 166The 167.Fn strfmon 168function 169conforms to 170.St -p1003.1-2001 . 171The 172.Fn strfmon_l 173function conforms to 174.St -p1003.1-2008 . 175.Sh AUTHORS 176.An -nosplit 177The 178.Fn strfmon 179function was implemented by 180.An Alexey Zelkin Aq Mt phantom@FreeBSD.org . 181.Pp 182This manual page was written by 183.An Jeroen Ruigrok van der Werven Aq Mt asmodai@FreeBSD.org 184based on the standards' text. 185.Sh BUGS 186The 187.Fn strfmon 188function does not correctly handle multibyte characters in the 189.Fa format 190argument. 191