From cdd9d92dade61a6b5c37b758e9533a076bb5a2de Mon Sep 17 00:00:00 2001 From: Jose Luis Duran Date: Tue, 8 Nov 2022 17:36:57 -0300 Subject: [PATCH] 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 924c82109a6..1ddfb77cb0a 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 +#include +#include + +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