HUMANIZE_NUMBER(3)
π NAME π
okay so this is the HUMANIZE_NUMBER(3) manual page, and the main character is humanize_number β format a number into a human readable form. periodt. π
π§ LIBRARY π§
System Utilities Library (libutil, -lutil) β yes bestie, that's the one. π«Ά
β¨ SYNOPSIS β¨
#include <libutil.h>
int
humanize_number(char *buf, size_t len, int64_t number,
const char *suffix, int scale, int flags);
π DESCRIPTION π
So humanize_number() takes the signed 64-bit quantity in number and formats it into buf. A space and then suffix is appended to the end. The buffer pointed to by buf must be at least len bytes long. no cap. β¨
If the formatted number (including suffix) would be too long to fit into buf, then it divides number by 1024 until it will. In this case, prefix suffix with the appropriate designator. humanize_number() follows the traditional computer science conventions by default, rather than the IEE/IEC (and now also SI) power of two convention or the power of ten notion. This behaviour however can be altered by specifying the HN_DIVISOR_1000 and HN_IEC_PREFIXES flags. π
The traditional (default) prefixes are:
- (note),
kiloβ multiplier1024; multiplier 1000x:1000. M,megaβ multiplier1048576; multiplier 1000x:1000000.G,gigaβ multiplier1073741824; multiplier 1000x:1000000000.T,teraβ multiplier1099511627776; multiplier 1000x:1000000000000.P,petaβ multiplier1125899906842624; multiplier 1000x:1000000000000000.E,exaβ multiplier1152921504606846976; multiplier 1000x:1000000000000000000.
Note: An uppercaseKindicates a power of two, a lowercaseka power of ten. π«Ά
The IEE/IEC (and now also SI) power of two prefixes are:
Ki,kibiβ multiplier1024.Mi,mebiβ multiplier1048576.Gi,gibiβ multiplier1073741824.Ti,tebiβ multiplier1099511627776.Pi,pebiβ multiplier1125899906842624.Ei,exbiβ multiplier1152921504606846976.
The len argument must be at least 4 plus the length of suffix, in order to ensure a useful result is generated into buf. To use a specific prefix, specify this as scale (multiplier = 1024 ^ scale; when HN_DIVISOR_1000 is specified, multiplier = 1000 ^ scale). This cannot be combined with any of the scale flags below. π
The following flags may be passed in scale:
HN_AUTOSCALEβ Format the buffer using the lowest multiplier possible.HN_GETSCALEβ Return the prefix index number (the number of timesnumbermust be divided to fit) instead of formatting it to the buffer.
The following flags may be passed in flags:
HN_DECIMALβ If the final result is less than10, display it using one decimal place.HN_NOSPACEβ Do not put a space betweennumberand the prefix.HN_Bβ UseB(bytes) as prefix if the original result does not have a prefix.HN_DIVISOR_1000β Dividenumberwith1000instead of1024.HN_IEC_PREFIXESβ Use the IEE/IEC notion of prefixes (Ki,Mi,Gi...). This flag has no effect whenHN_DIVISOR_1000is also specified.
π RETURN VALUES π
Upon success, the humanize_number function returns the number of characters that would have been stored in buf (excluding the terminating NUL) if buf was large enough, or -1 upon failure. Even upon failure, the contents of buf may be modified. If HN_GETSCALE is specified, the prefix index number will be returned instead. π
π STANDARDS π
The HN_DIVISOR_1000 and HN_IEC_PREFIXES flags conform to ISO/IEC Std 80000-13:2008 and IEEE Std 1541-2002. iconic. β¨
π¦ HISTORY π¦
The humanize_number() function first appeared in NetBSD 2.0 and then in FreeBSD 5.3. The HN_IEC_PREFIXES flag was introduced in FreeBSD 9.0. πΈ
π CAVEATS π
For numbers greater than 999, using buffer length of 4 and less can cause rounding errors. When using HN_IEC_PREFIXES, the same error occurs for buffer length of 5 or less. be careful bestie, fr fr. π
xoxo, this page is from Debian, dated October 7, 2013 β slay and goodbye ππ
π¦ where this page comes from
- nixpkgs unstable: libutil 73
- Copyright (c) 1999, 2002 The NetBSD Foundation, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms