- NetBSD Manual Pages
STRPCT(3) NetBSD Library Functions Manual STRPCT(3)
Powered by man-cgi (2021-03-02).
Maintained for NetBSD
by Kimmo Suominen.
Based on man-cgi by Panagiotis Christias.
strpct, strspct -- decimal percent formatters
System Utilities Library (libutil, -lutil)
strpct(char *buf, size_t bufsiz, uintmax_t numerator,
uintmax_t denominator, size_t precision);
strspct(char *buf, size_t bufsiz, intmax_t numerator,
intmax_t denominator, size_t precision);
The strpct() function formats the fraction represented by numerator and
denominator into a percentage representation with given number of digits
of precision without using floating point arithmetic.
strpct() and strspct() always return a pointer to a NUL-terminated
(unless buflen is 0) formatted string which is placed in buf and is up to
buflen characters. If there was an overflow, the formatted string will
reflect that precision loss.
strpct(buf, buflen, 1, 16, 3);
strpct(buf, buflen, 1, 2, 0);
strpct() was originally implemented in csh(1) for NetBSD 1.3. It printed
into a static buffer, was not locale aware, handled unsigned long num-
bers, and printed a ``%'' at the end of the number. Other programs such
as df(1) and time(1) started using it. strpct() and strspct() appeared
separately in libutil for NetBSD 6.0.
Erik E. Fair <firstname.lastname@example.org>
NetBSD 9.99 January 7, 2012 NetBSD 9.99