Unix/Linux Go Back    

NetBSD 6.1.5 - man page for strspct (netbsd section 3)

Linux & Unix Commands - Search Man Pages
Man Page or Keyword Search:   man
Select Man Page Set:       apropos Keyword Search (sections above)

STRPCT(3)			   BSD Library Functions Manual 			STRPCT(3)

     strpct, strspct -- decimal percent formatters

     System Utilities Library (libutil, -lutil)

     #include <util.h>

     char *
     strpct(char *buf, size_t bufsiz, uintmax_t numerator, uintmax_t denominator,
	 size_t precision);

     char *
     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) for-
     matted string which is placed in buf and is up to buflen characters.  If there was an over-
     flow, the formatted string will reflect that precision loss.

	   strpct(buf, buflen, 1, 16, 3);
	   => "6.250"
	   strpct(buf, buflen, 1, 2, 0);
	   => "50"

     strpct() was originally implemented in csh(1) for NetBSD 1.3.  It printed into a static buf-
     fer, was not locale aware, handled unsigned long numbers, 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 <fair@netbsd.org>

BSD					 January 7, 2012				      BSD
Unix & Linux Commands & Man Pages : ©2000 - 2018 Unix and Linux Forums

All times are GMT -4. The time now is 04:37 AM.