Date: Wed, 25 Jan 2023 09:03:24 GMT From: Konstantin Belousov <kib@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: git: cdd9d92dade6 - main - strfmon(3): Add an EXAMPLES section Message-ID: <202301250903.30P93Obg027075@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=cdd9d92dade61a6b5c37b758e9533a076bb5a2de commit cdd9d92dade61a6b5c37b758e9533a076bb5a2de Author: Jose Luis Duran <jlduran@gmail.com> AuthorDate: 2022-11-08 20:36:57 +0000 Commit: Konstantin Belousov <kib@FreeBSD.org> CommitDate: 2023-01-25 09:02:55 +0000 strfmon(3): Add an EXAMPLES section Reviewed by: kib MFC after: 1 week --- lib/libc/stdlib/strfmon.3 | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/lib/libc/stdlib/strfmon.3 b/lib/libc/stdlib/strfmon.3 index 924c82109a68..1ddfb77cb0ac 100644 --- a/lib/libc/stdlib/strfmon.3 +++ b/lib/libc/stdlib/strfmon.3 @@ -149,6 +149,31 @@ The .Fn strfmon_l function returns the same values as .Fn strfmon . +.Sh EXAMPLES +The following example will format the value +.Dq Li 1234567.89 +to the string +.Dq Li $1,234,567.89 : +.Bd -literal -offset indent +#include <stdio.h> +#include <monetary.h> +#include <xlocale.h> + +int +main() +{ + char string[100]; + double money = 1234567.89; + + if (setlocale(LC_MONETARY, "en_US.UTF-8") == NULL) { + fprintf(stderr, "Unable to setlocale().\\n"); + return (1); + } + + strfmon(string, sizeof(string) - 1, "%n", money); + printf("%s\\n", string); +} +.Ed .Sh ERRORS The .Fn strfmon
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202301250903.30P93Obg027075>